I have the following code:
people = {'Bob' : {'phone' : '12',
'birthday' : 'May',
'address' : 'ABC',
'interests' : ['a', 'b', 'c']},
'Mary' : {'phone' : '13',
'birthday' : 'April',
'address' : 'CBA',
'interests' : ['d', 'e', 'f']},
response = ['']
wrong = "I don't know. Try again or type 'quit' to get out: "
while response[0] != 'quit':
response = raw_input("Please enter who you're looking for, or type 'quit' to get out: ").split()
try:
print "%s's %s is %s" % (response[0], response[1], people[response[0]][response[1]])
except KeyError:
print wrong,
I’d like to make it so the input can be in any case and still generate the correct output.
E.g.
'Mary phone', 'mary Phone', 'MARY PHONE'
all give
Mary's phone number is 13.
You should use
capitalize()andlower()You should change the
'bob'key to'Bob', if you go this route…Alternatively, you can save a few more CPU cycles if you reuse results, as mentioned by rubik below.