生日检索

》题目要求

  》》用户输入一个姓名

  》》打印出这个姓名对应的人的生日

》程序实现

 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)
View Code

》改进方案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)
改进程序1

》改进方案2

  新录入的数据没能存储下来,待更新中......

转载于:https://www.cnblogs.com/NeverCtrl-C/p/6128828.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值