私は次のコードを持っています:
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.