mercredi 13 mai 2015

If key in dictionary returning false when key exists

Python 3.2

This might be really stupid but:

items = {'1': 'ACK', '2': 'RELQ', '3': 'COM'}
choice = input('Choose an option:\n1.ACK\n2.RELQ\n3.COM\n')
print(choice)
if choice in items:
    print(choice)
    option = items[choice]
else:
    print('Input not recognized')

If you type 1 it keeps returning

1
Input not recognized

The choice in items is returning a false?

This should be really easy but I just cant see what it is.

Aucun commentaire:

Enregistrer un commentaire