#encoding=utf-8
print("欢迎使用Pyhon名片系统")
#定义列表存储名片信息
list_card = [{'编号':1,'姓名':'zhanshi','电话':'110'},{'编号':2,'姓名':'战士','电话':'119'}]
while True:
print("*"*20)
#名片系统功能
print("添加名片【1】")
print("删除名片【2】")
print("修改名片【3】")
print("查询名片【4】")
print("查询所有【5】")
print("销毁系统【6】")
print("退出系统【7】")
print("*"*20)
str1 = input("请输入选择的功能:")
if str1 == '1':
id = int(input("请输入新编号:"))
name = input("请输入新姓名:")
telphone = input("请输入新电话:")
#定义字典
dict_card = {}
dict_card['编号'] = id
dict_card['姓名'] = name
dict_card['电话'] = telphone
#将字典数据插入到列表中
list_card.append(dict_card)
print("添加完毕")
elif str1 == '2':
name = input("请输入删除的姓名:")
flag = False
for dict_list in list_card:
if dict_list['姓名'] == name:
flag = True
list_card.remove(dict_list)
#break
if flag:
print("姓名:%s已删除"%name)
else:
print("没有找到%s姓名,无法删除"%name)
continue #删除后功能继续
elif str1 == '3':
name = input("请输入修改前的姓名:")
#默认不存在标志
flag = False
for dict_list in list_card:
if dict_list['姓名'] == name:
new_id = int(input("请输入新编号:"))
new_name = input("请输入新姓名:")
new_telphone = input("请输入新电话:")
dict_list['编号'] = new_id
dict_list['姓名'] = new_name
dict_list['电话'] = new_telphone
flag = True
if flag:
print("姓名:%s已修改OK"%name)
else:
print("没有找到%s姓名,无法修改"%name)
continue
elif str1 == '4':
name = input("请输入查询的姓名:")
#默认不存在标志
flag = False
print("="*20)
for dict_list in list_card:
if dict_list['姓名'] == name:
flag= True
if flag:
print("编号:%d,姓名:%s,电话:%s"%(dict_list['编号'],dict_list['姓名'],dict_list['电话']))
else:
print("没有找到%s"%name)
print("="*20)
continue
elif str1 == '5':
print("="*20)
for dict in list_card:
for key,value in dict.items():
print("%3s:%s"%(key,value))
print("="*20)
elif str1 =='6':
del list_card
print('名片系统销毁!!!')
break
elif str1 == '7':
break
else:
print("请按提示使用名片系统")
网站题目:python小白之路(特性语法三应用名片管理器项目)
链接URL:
http://cxhlcq.com/article/jhgppi.html