python开发--信息处理系统

时间:2023-04-06 09:39:14
#!/usr/bin/python
card_list=[] #定义列表变量
def show_menu():
print("*" * 10)
print("名片管理系统 V0.1")
print("01,新增名片")
print("02,显示名片")
print("03,搜索名片")
print("退出系统")
print("*" * 10)
def menu_1():
"""新增名片"""
name_str = input("请输入姓名:")
phone = input("请输入电话:")
qq = input("请输入QQ:")
email = input("请输入邮箱:")
card_dict = { #获取的指存入字典
"name": name_str,
"phone": phone,
"qq": qq,
"emile": email
}
card_list.append(card_dict) #存入列表
print(card_list)
print("添加 %s 的名片成功" % name_str)
def menu_2():
"""显示所有文件"""
print("*" * 10)
if len(card_list) == 0:
print("当前没有任何名片,请进行添加")
return
for num in ["姓名","电话","QQ","邮箱"]:
print(num,end="\t\t")
print("")
for card_s in card_list: #格式化输出内容
print("==" * 5)
print("%s\t\t%s\t\t%s\t%s" % (card_s["name"],
card_s["phone"],
card_s["qq"],
card_s["emile"]))
print("==" * 5)
def menu_3():
"""s搜索文件"""
print("搜索名片")
find_name = input("请输入要搜索的姓名: ")
for card_dict in card_list:
if card_dict["name"] == find_name:
print("姓名\t\t电话\t\tQQ\t\t邮箱")
print("%s\t\t%s\t\t%s\t%s" % (card_dict["name"],
card_dict["phone"],
card_dict["qq"],
card_dict["emile"]))
deal_crad(card_dict) #传参
break
else:
print("没有寻找到 %s " % find_name) def deal_crad(find_dict): #定义修改操作
print(find_dict)
action_atr = input("请输入你所需要执行的操作:1 修还 2 删除 0 返回 :")
if action_atr == "" :
find_dict["name"] = input_card_onfo(find_dict["name"],"姓名:")
find_dict["phone"] = input_card_onfo(find_dict["name"],"电话:")
find_dict["qq"] = input_card_onfo(find_dict["name"],"QQ:")
find_dict["emile"] = input_card_onfo(find_dict["name"],"邮箱:")
print("修改名片成功")
elif action_atr == "" :
card_list.remove(find_dict)
print("删除成功")
def input_card_onfo(dict_value,tip_message): #定义用户不输出返回值
result_str = input(tip_message)
if len(result_str) >0:
return result_str
else:
return dict_value while True:
show_menu()
print()
action_atr = input("请输入需要现在的操作:")
if action_atr in ["","",""]:
if action_atr == "":
print("第1个菜单")
menu_1()
elif action_atr == "":
print("第2个菜单")
menu_2()
else:
print("第2个菜单")
menu_3()
elif action_atr == "":
print("欢迎再次使用!")
print("正在退出....")
exit(1)
else:
print("您输入的操作有误,请重新输入: ")