Python Type Error Unsupported Operand

Xivilai

I have a sample program here that is returning the following error when I run it and select an option but I don't see the problem.

TypeError: unsupported operand type(s) for -: 'str' and 'int'

#Exception Handling

#If you haven't seen them before, you're not trying hard enough. What are they? Errors. Exceptions. Problems. Know what I'm talking about? I got it with this program:

#Code Example 1 - buggy program
def menu(list, question):
    for entry in list:
        print (1 + list.index(entry),)
        print (")" + entry)

    return input(question) -1

answer = menu(['A','B','C','D','E','F','H','I'],\
'Which letter is your favourite?')

print ('You picked answer ' + (answer + 1))
furas

If you use Python3 then input(question) returns string '1', '2', etc. You have to convert it into number int(input(question)).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Type error: unsupported operand

From Dev

Unsupported operand type in Python

From Dev

TypeError: unsupported operand type in Python

From Dev

Python Error TypeError: unsupported operand type(s) for +: 'function' and 'function'

From Dev

Python Error: unsupported operand type(s) for +: 'int' and 'NoneType'

From Dev

Python Error : unsupported operand type(s) for +: 'int' and 'datetime.timedelta'

From Dev

python error; unsupported operand type(s) for +: 'int' and 'str'

From Dev

Python Error: unsupported operand type(s) for +: 'int' and 'NoneType'

From Dev

Python error: unsupported operand type(s) for -: 'float' and 'NoneType'

From Dev

Unsupported operand type(s) for +: 'float' and 'str' error

From Dev

Euclidean Distance Error: unsupported operand type

From Dev

Error message: unsupported operand type(s) for ___

From Dev

Unsupported operand type(s) for *: 'NoneType' and 'NoneType' (Python)

From Dev

Python - Unsupported Operand type(s) for +: 'int' and 'list'

From Dev

Python - Unsupported Operand Type(s) for -: 'int' and 'str'

From Dev

Python: unsupported operand type(s) for /: 'tuple' and 'float'

From Dev

Unsupported operand in if/else statement error in Python

From Dev

type error: unsupported operand type(s) for +: 'WebElement' and 'WebElement' for selenium

From Dev

Python 2.7 TypeError: Unsupported operand type(s) for %:'None type' and str

From Dev

Solving "error: Unsupported left operand type for + ("Iterable[str]") [operator]"

From Dev

Unsupported Operand Type Error with scipy.optimize.curve_fit

From Dev

Django-cms error "unsupported operand type(s) for +: 'set' and 'tuple'"

From Dev

Unsupported operand type error when trying to multiply function parameter by an integer

From Dev

Solving "error: Unsupported left operand type for + ("Iterable[str]") [operator]"

From Dev

Unsupported Operand Type Error with scipy.optimize.curve_fit

From Dev

Django-cms error "unsupported operand type(s) for +: 'set' and 'tuple'"

From Dev

getting error unsupported operand type(s) for +: 'int' and 'str'

From Dev

Error in pip: unsupported operand type(s) for -=: 'Retry' and 'int'

From Dev

Why does exp**2 produce the error "unsupported operand type(s) for **"?

Related Related

  1. 1

    Type error: unsupported operand

  2. 2

    Unsupported operand type in Python

  3. 3

    TypeError: unsupported operand type in Python

  4. 4

    Python Error TypeError: unsupported operand type(s) for +: 'function' and 'function'

  5. 5

    Python Error: unsupported operand type(s) for +: 'int' and 'NoneType'

  6. 6

    Python Error : unsupported operand type(s) for +: 'int' and 'datetime.timedelta'

  7. 7

    python error; unsupported operand type(s) for +: 'int' and 'str'

  8. 8

    Python Error: unsupported operand type(s) for +: 'int' and 'NoneType'

  9. 9

    Python error: unsupported operand type(s) for -: 'float' and 'NoneType'

  10. 10

    Unsupported operand type(s) for +: 'float' and 'str' error

  11. 11

    Euclidean Distance Error: unsupported operand type

  12. 12

    Error message: unsupported operand type(s) for ___

  13. 13

    Unsupported operand type(s) for *: 'NoneType' and 'NoneType' (Python)

  14. 14

    Python - Unsupported Operand type(s) for +: 'int' and 'list'

  15. 15

    Python - Unsupported Operand Type(s) for -: 'int' and 'str'

  16. 16

    Python: unsupported operand type(s) for /: 'tuple' and 'float'

  17. 17

    Unsupported operand in if/else statement error in Python

  18. 18

    type error: unsupported operand type(s) for +: 'WebElement' and 'WebElement' for selenium

  19. 19

    Python 2.7 TypeError: Unsupported operand type(s) for %:'None type' and str

  20. 20

    Solving "error: Unsupported left operand type for + ("Iterable[str]") [operator]"

  21. 21

    Unsupported Operand Type Error with scipy.optimize.curve_fit

  22. 22

    Django-cms error "unsupported operand type(s) for +: 'set' and 'tuple'"

  23. 23

    Unsupported operand type error when trying to multiply function parameter by an integer

  24. 24

    Solving "error: Unsupported left operand type for + ("Iterable[str]") [operator]"

  25. 25

    Unsupported Operand Type Error with scipy.optimize.curve_fit

  26. 26

    Django-cms error "unsupported operand type(s) for +: 'set' and 'tuple'"

  27. 27

    getting error unsupported operand type(s) for +: 'int' and 'str'

  28. 28

    Error in pip: unsupported operand type(s) for -=: 'Retry' and 'int'

  29. 29

    Why does exp**2 produce the error "unsupported operand type(s) for **"?

HotTag

Archive