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))
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.
Comments