名片管理系统
主要涵盖知识点:
列表可存放数据的样式对于字典的用法, 怎样添加数据格式化点位符if 判断分支流程的走向函数分模块的意识
card_list
= []
def show_menu():
"""显示菜单"""
print('*' * 50)
print('欢迎使用[名片管理系统]')
print('')
print('1. 新增名片')
print('2. 删除名片')
print('3. 修改名片')
print('4. 搜索名片')
print('5. 显示全部')
print('0. 退出系统')
print('*' * 50)
def new_card():
"""新增名片"""
print('*' * 50)
print('新增名片')
card_dict
= {}
name
= input('请输入姓名: ')
mobile
= input('请输入电话: ')
qq
= input('请输入QQ: ')
email
= input('请输入邮箱: ')
card_dict
['name'] = name
card_dict
['mobile'] = mobile
card_dict
['QQ'] = qq
card_dict
['email'] = email
card_list
.append
(card_dict
)
print(card_list
)
print('添加%s的名片成功' % name
)
def del_dict():
"""删除名片"""
print('*' * 50)
print('删除名片')
find_name
= input('请问你想删除哪一个名片: ')
if len(card_list
) < 1:
print('sorry, 没有找到%s' % find_name
)
return
else:
for card_dict
in card_list
:
if card_dict
['name'] == find_name
:
card_list
.remove
(card_dict
)
print('删除%s名片成功' % find_name
)
break
else:
print('sorry, 没有找到%s' % find_name
)
def modify_dict():
"""修改名片"""
print('*' * 50)
print('修改名片')
find_name
= input('请问你想修改哪一个名片: ')
if len(card_list
) < 1:
print('sorry, 没有找到%s' % find_name
)
return
else:
for card_dict
in card_list
:
if card_dict
['name'] == find_name
:
name
= input('请输入姓名: ')
mobile
= input('请输入电话: ')
QQ
= input('请输入QQ: ')
email
= input('请输入邮箱: ')
card_dict
['name'] = name
card_dict
['mobile'] = mobile
card_dict
['QQ'] = QQ
card_dict
['email'] = email
print('修改%s成功' % card_dict
['name'])
break
else:
print('sorry, 没有找到%s' % find_name
)
def search_card():
"""查询个人名片"""
print('*' * 50)
print('搜索名片')
find_name
= input('请输入你要查找的姓名: ')
if len(card_list
) < 1:
print('sorry, 没有找到%s' % find_name
)
return
else:
for card_dict
in card_list
:
if card_dict
['name'] == find_name
:
print('姓名\t\t电话\t\tQQ\t\t邮箱')
print('=' * 50)
print('%s\t\t%s\t\t%s\t\t%s' % (
card_dict
['name'], card_dict
['mobile'], card_dict
['QQ'], card_dict
['email']))
break
else:
print('sorry, 没有找到%s' % find_name
)
def show_all():
"""显示所有的名片"""
print('*' * 50)
print('显示所有的名片')
if len(card_list
) < 1:
print('当前还没有任何名片记录, 请使用新增功能添加名片')
return
print('姓名\t\t电话\t\tQQ\t\t邮箱')
print('=' * 50)
for card_dict
in card_list
:
print('%s\t\t%s\t\t%s\t\t%s' % (card_dict
['name'], card_dict
['mobile'], card_dict
['QQ'], card_dict
['email']))
def main():
"""这里是主函数, 整个程序的主要函数入口在这里, 由这里走向不同的分支方向"""
while True:
action_str
= input("请选择希望执行的操作: ")
print("你选择的操作是 %s" % action_str
)
if action_str
in ["1", "2", "3", '4', '5']:
if action_str
== "1":
new_card
()
elif action_str
== "2":
del_dict
()
elif action_str
== "3":
modify_dict
()
elif action_str
== '4':
search_card
()
else:
show_all
()
elif action_str
== "0":
print("欢迎再次使用【名片管理系统】:")
break
else:
print("输入错误,请重新输入:")
if __name__
== '__main__':
show_menu
()
main
()
转载请注明原文地址: https://yun.8miu.com/read-18310.html