我有以下代码:
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,
我想让它在任何情况下都可以输入并且仍然生成正确的输出。例如
'Mary phone', 'mary Phone', 'MARY PHONE'
都给
Mary's phone number is 13.