#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("請按提示使用名片系統")
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。