在基础班即将结束的时候,看到旧教材视频里面有一个叫做名片管理的基础项目案例,感觉算是自己能力范围之内,于是尝试的打了一遍,和大家分享一下,希望有人指出不足和改进的地方。
def star_menu():
print("*"*50)
print("欢迎使用【名片管理系统】v1.0")
print("")
print("1.新建名片")
print("2.显示全部")
print("3.查询名片")
print("")
print("0.退出系统")
print("*"*50)
def star_word():
print("您选择的操作是%s" % order_number)
print("-" * 50)
name_card_list = []
while True:
star_menu()
order_number = input("请选择操作功能:")
if order_number == "1":
star_word()
print("功能:新建名片")
name = input("请输入姓名:")
number = input("请输入电话:")
number_qq = input("请输入 qq 号码:")
new_card_diet = {"姓名": name, "电话": number, "qq号码": number_qq}
name_card_list.append(new_card_diet)
print("成功添加 %s 的名片" % name)
elif order_number == "2":
star_menu()
print("功能:显示全部")
print("姓名\t\t 电话\t\t qq号码")
for show_card in name_card_list:
print("%s\t\t %s\t\t%s" % (show_card["姓名"], show_card["电话"], show_card["qq号码"]))
elif order_number == "3":
star_word()
print("功能:查询名片")
search_name = input("请输入你需要查找的姓名:")
n = 0
for show_card_2 in name_card_list:
if show_card_2["姓名"] == search_name:
n = 1
print("姓名\t\t 电话\t\t qq号码")
print("%s\t\t %s\t\t%s" % (show_card_2["姓名"], show_card_2["电话"], show_card_2["qq号码"]))
while True:
order_number = input("请选择操作功能:(更改1/删除2/返回0)")
if order_number == "1":
star_word()
n = name_card_list.index(show_card_2)
print("功能:更改名片")
name = input("请输入姓名:")
number = input("请输入电话:")
number_qq = input("请输入 qq 号码:")
if len(name) == 0:
name = show_card_2["姓名"]
if len(number) == 0:
number = show_card_2["电话"]
if len(number_qq) == 0:
number_qq = show_card_2["qq号码"]
show_card_2 = {"姓名": name, "电话": number, "qq号码": number_qq}
name_card_list[n] = show_card_2
print("成功修改 %s 的名片" % show_card_2["姓名"])
print("%s\t\t %s\t\t%s" % (show_card_2["姓名"], show_card_2["电话"], show_card_2["qq号码"]))
elif order_number == "2":
name_card_list.remove(show_card_2)
print("您已成功删除")
break
elif order_number == "0":
break
else:
print("您输入有误请重新输入")
if n == 0:
print("您查找的姓名未登记")
elif order_number == "0":
break
else:
print("您输入有误请重新输入")
continue
|
|