According to the comment, you want that if the user types a number between 1 and 5 or 'a' it's print "you go right".
So items
should be a list of strings, not a dictionnary nor a set. List are defined by []
.
Then, it's always best to cast your inputs (str(input())
to cast to a string for example).
Finally, indices in Python starts at 0 not 1, consequently you should assign items[choice-1]
instead of items[choice]
(else it would generate an error if the user's choice is 5). I also added another if
statements as items['a']
means nothing for a list.
Which gives:
items = ['1', '2', '3', '4', '5', 'a']
choice = str(raw_input("Select a number: "))
if choice in items:
if choice is not 'a':
the_choice = items[int(choice)-1]
print('you go right')
else:
print('you go left')
It will return you go right
if the user writes 1,2,3,4,5 or 'a' ; you go left
for all the other cases.