本文实例为大家分享了python实现名片管理系统源代码,供大家参考,具体内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
import os def print_menu(): print ( "*" * 50 ) print ( " 名片管理系统" ) print ( " 1.添加一个新名片" ) print ( " 2.删除一个名片信息" ) print ( " 3.修改一个名片信息" ) print ( " 4.查找一个名片信息" ) print ( " 5.显示添加过的名片信息" ) print ( " 6.保存添加的名片信息" ) print ( " 7.退出系统" ) print ( "*" * 50 ) card_infor = [] def add_new_card_infor(): new_name = input ( "请输入要添加的名字:" ) new_qq = input ( "请输入qq:" ) new_weixin = input ( "请输入微信号:" ) new_position = input ( "请输入工作职位" ) new_addr = input ( "请输入工作地址" ) """创建一个字典来存放添加的内容""" new_infor = {} new_infor[ 'name' ] = new_name new_infor[ 'qq' ] = new_qq new_infor[ 'weixin' ] = new_weixin new_infor[ 'position' ] = new_position new_infor[ 'addr' ] = new_addr """将字典刚入一个列表中""" global card_infor card_infor.append(new_infor) def del_card_infor(): del_name = input ( "请输入要删除的名片" ) global card_infor for temp in card_infor: if del_name = = temp[ 'name' ]: print ( "删除的名片如下" ) card_infor.remove(temp) print ( "%s\t\t%s\t\t%s\t\t%s\t\t%s" % (temp[ 'name' ],temp[ 'qq' ],temp[ 'weixin' ],temp[ 'position' ],temp[ 'addr' ])) else : print ( "不存在" ) return del_card_infor() def change_care_infor(): change_name_card = input ( "请输入需要修改的名片名字" ) global card_infor for temp in card_infor: if change_name_card = = temp[ 'name' ]: new_name = input ( "请输入要修改的名字" ) new_qq = input ( "请输入要修改的qq" ) new_weixin = input ( "请输入要修改的微信" ) new_position = input ( "请输入要修改的职业" ) new_addr = input ( "请输入要修改的地址" ) temp[ 'name' ] = new_name temp[ 'qq' ] = new_qq temp[ 'weixin' ] = new_weixin temp[ 'position' ] = new_position temp[ 'addr' ] = new_addr print ( "修改成功" ) break else : print ( "您要修改的名片不存在" ) def find_card_infor(): global card_infor find_name = input ( "请输入要在查找的内容\n" ) find = 0 for temp in card_infor: if find_name = = temp[ 'name' ]: print ( "查询成功\n" ) print ( "%s\t\t%s\t\t%s\t\t%s\t\t%s" % (temp[ 'name' ],temp[ 'qq' ],temp[ 'weixin' ],temp[ 'position' ],temp[ 'addr' ])) find = 1 break else : print ( "您要查询的名片不存在,请重新输入" ) return find_card_infor() def display_card_infor(): global card_infor print ( "姓名\t\tqq\t\t微信\t\t工作\t\t住址" ) for temp in card_infor: print ( "%s\t\t%s\t\t%s\t\t%s\t\t%s" % (temp[ 'name' ],temp[ 'qq' ],temp[ 'weixin' ],temp[ 'position' ],temp[ 'addr' ])) def save_card_infor(): global card_infor f = open ( "save_card.data" , "w" ) f.write( str (card_infor)) f.close() def load_card_infor(): """恢复保存的信息""" global card_infor try : f = open ( 'save_card.data' ) card_infor = eval (f.read()) f.close() except exception: pass def main(): load_card_infor() """把恢复保存的信息加载到程序中""" print_menu() """加载首页操作页面""" while true: num = int ( input ( "请输入你要选择的功能序号" )) if (num = = 1 ): add_new_card_infor() elif (num = = 2 ): del_card_infor() elif (num = = 3 ): change_care_infor() elif (num = = 4 ): find_card_infor() elif (num = = 5 ): display_card_infor() elif (num = = 6 ): save_card_infor() elif (num = = 7 ): break else : print ( "输入有误,请重新输入" ) print () if __name__ = = "__main__" : main() |
运行界面
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_41337627/article/details/84929151