生日检索
》题目要求
》》用户输入一个姓名
》》打印出这个姓名对应的人的生日
》程序实现
1 birthday = {"王江智":"1996/12/26", 2 "杨顺裙":"1996/09/04", 3 "王杨梅":"1990/10/15", 4 "王杨灿":"1992/02/04", 5 "王杨帅":"1993/10/03", 6 "杨玉林":"2013/10/13"} 7 8 while True: 9 name = input("Please input the name of one person whose birthday you want to know:") 10 if name == "": 11 break 12 if name in birthday: 13 print("The birthday of "+name + " is "+birthday[name]) 14 else: 15 print("There is no birthday infomation of "+name)
》改进方案1
如果输入的姓名没有对应的生日,提醒用户是否要录入生日;
如果用户同意录入生日,那么用户下次再输入这个姓名是就会返回一个生日
三少想吃火锅啦,待更新...... 2017年1月8日10:17:33 更新
1 import sys 2 birthdays = { 3 "王杨1": "2990/10/15", 4 "王杨2": "1992/02/04", 5 "王杨4": "1993/10/03", 6 "杨3": "2013/10/13", 7 "杨5": "1993/11/05" 8 } 9 while True: 10 name = input("请输入姓名(exit表示退出):") 11 if "exit" == name: 12 sys.exit() 13 14 if name in birthdays: 15 print("The birthday of " + name + " is " + birthdays[name]) 16 else: 17 print("There is no information about " + name) 18 choose = input("Do you want to input the information of birthday about " + name + ":") 19 if ("y" == choose) or ("Y" == choose): 20 date = input("Please input some information about " + name + ":") 21 birthdays[name] = date 22 print("The database of birthdays has upgraded.") 23 print(birthdays)
》改进方案2
新录入的数据没能存储下来,待更新中......