十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
首先新建项目,包含主程序cards_main和工具库cards_tools:
为渝水等地区用户提供了全套网页设计制作服务,及渝水网站建设行业解决方案。主营业务为成都网站建设、网站设计、渝水网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
如下:
main函数主主要使用while和if实现4功能切换,切换的具体操作由cards_tools中的函数执行。不说了直接上代码,代码都比较简单:
(1)cards_main:
"""
File_name : cards_main.py
Author : jack
Date : 2018.7.18
Function : 名片管理系统主程序
"""
import cards_tools
while True:
cards_tools.cards_dis()
cards_input = input("请选择操作功能:")
if cards_input in ["1", "2", "3"]:
if cards_input == "1":
print("- " 20)
print("您选择输入的操作代码是: 1" )
cards_tools.cards_add()
elif cards_input == "2":
print("- " 20)
print("您选择输入的操作代码是: 2" )
cards_tools.cards_show_all()
elif cards_input == "3":
print("- " 20)
print("您选择输入的操作代码是: 3" )
cards_tools.cards_requ()
elif cards_input == "0":
print("您选择输入的操作代码是: 0" )
print("即将退出系统......\n" "已退出系统,欢迎您下次【名片管理系统】!")
break
else:
cards_input = input("输入错误,请重新输入:")
cards_tools.cards_dis()
#cards_input = input("输入错误,请重新输入:")
while True:
cards_input = input("输入错误,请重新输入:")
cards_tools.cards_dis()
if cards_input in ["1", "2", "3", "0"]:
if cards_input == "1":
print("- " 20)
print("您选择输入的操作代码是: 1")
cards_tools.cards_add()
break
if cards_input == "2":
print("- " 20)
print("您选择输入的操作代码是: 2")
cards_tools.cards_show_all()
break
if cards_input == "3":
print("- " 20)
print("您选择输入的操作代码是: 3")
cards_tools.cards_requ()
break
else:
# #print("返回主菜单")
break
break
(2)cards_tools:
"""
File_name : cards_main.py
Author : jack
Date : 2018.7.18
Function : 名片管理系统tools
"""
def cards_dis():
"""显示菜单"""
print(" " 20)
print("\t欢迎使用【名片管理系统 V1.0】\n"
"\t\t\t1. 新建名片\n" "\t\t\t2. 显示全部\n" "\t\t\t3. 查询名片\n\n" "\t\t\t0. 退出系统")
print(" " 20)
cards_list = []
def cards_add ():
"""新增名片"""
print("- " * 20 )
print("新增名片")
"""输入-整理成字典-将字典存储到列表中-提示输入成功"""
name_str = input("请输入姓名:")
gender_str = input("请输入性别:")
tel_int = input("请输入电话:")
add_str = input("请输入地址:")
cards_dict = {"name" : name_str,
"gender" : gender_str,
"telephone" : tel_int,
"address" : add_str}
cards_list.append(cards_dict)
print(cards_list)
print("%s 的名片新增成功!" % name_str)
def cards_show_all ():
"""显示全部名片"""
print("- " 20)
print("显示所有名片")
if len(cards_list) == 0:
print("当前系统中没有名片,请新增名片!")
else:
print("=" 40)
#print("姓名\t\t" "性别\t\t" "电话\t\t" "地址")
for name in ("姓名","性别","电话","地址"):
print(name, end="\t\t")
print(" ")
for cards_dict in cards_list:
print("%s\t\t%s\t\t%s\t\t%s" % (cards_dict["name"],
cards_dict["gender"],
cards_dict["telephone"],
cards_dict["address"]))
print(cards_dict)
print("=" * 40)
def cards_requ ():
"""查询名片"""
print("- " 20)
print("查询名片")
find_name = input("请输入要搜索的姓名:")
if len(cards_list) == 0:
print("抱歉!没找到用户 %s 的信息, 请新增!" % find_name)
else:
for search_name in cards_list:
if search_name["name"] == find_name:
print("找到 %s 的信息了。" % find_name)
print("=" 40)
for name in ("姓名", "性别", "电话", "地址"):
print(name, end="\t\t")
print(" ")
print("s%\t\ts%\t\ts%\t\ts%" % (search_name["name"],
search_name["gender"],
search_name["telephone"],
search_name["address"]))
print("=" * 40)
cards_deal(search_name)
break
else:
print("抱歉!没找到用户 %s 的信息。" % find_name)
def cards_deal(find_dict):
"""修改和删除名片"""
deal_cards = input("请选择要进行的操作: [1] 删除\t\t[2] 修改\t\t[3] 返回主菜单\n")
if deal_cards in ["1","2","3"]:
if deal_cards == "1":
cards_list.remove(find_dict)
print("删除用户 %s 名片成功!" % (find_dict["name"]))
if deal_cards == "2":
find_dict["name"] = cards_mod(find_dict["name"], "请输入修改后的姓名:")
find_dict["gender"] = cards_mod(find_dict["gender"], "请输入修改后的性别:")
find_dict["telephone"] = cards_mod(find_dict["telephone"], "请输入修改后的电话:")
find_dict["address"] = cards_mod(find_dict["address"], "请输入修改后的地址:")
print("用户 %s 的名片修改成功!" % find_dict["name"])
else:
print("输入错误,请重新输入!")
def cards_mod(cards_value, cards_new):
result = input(cards_new)
if len(result) > 0:
return result
else:
return cards_value
本人也是新手,欢迎大佬们批评指正。