源代码如下:
#coding:utf8 '''一个简答的数据库''' people={'Alice':{'phone':'2314', 'addr':'Foo drive23'}, 'Beth':{'phone':'4567', 'addr':'Fac nihao12'}, 'Cecil':{'phone':'2132', 'addr':'6543'}} labels={'phone':'phone number', 'addr':'address'} name=input('请输入名字:\n') request=input('phone number(p) or address(a):\n') if request=='p':key='phone' if request=='a':key='addr' if name in people: print("%s 's %s is %s."%(name,labels[key],people[name][key]))
运行结果:
请输入名字: Alice phone number(p) or address(a): a Alice 's address is Foo drive23.