-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathAddress-book.py
More file actions
60 lines (50 loc) · 1.76 KB
/
Copy pathAddress-book.py
File metadata and controls
60 lines (50 loc) · 1.76 KB
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
def insert():
name = input('请输入新建的联系人姓名: ')
phone = input('请输入电话号码: ')
telbook[str(name)] = str(phone)
print("Records insert successfully!\nHere are all records:")
print(telbook)
def delete():
name = input('请输入要删除的联系人姓名: ')
del telbook[name]
print('Delete successfully!\nHere are new records:')
print(telbook)
def change():
name = input('请输入要修改号码的联系人姓名: ')
for key in sorted(telbook.keys()):
if str(name) == key:
phone = input('请输入新的电话号码: ')
telbook[str(key)] = str(phone)
print('Change successfully!\nHere are new records:')
print(telbook)
return
print('该联系人不存在,请查证!')
def show_all():
print('Here are all records:')
print(telbook)
def search():
name = input('请输入联系人姓名: ')
for key in sorted(telbook.keys()):
if str(name) == key:
print('联系人 '+key+' 的电话号码为: '+telbook[key])
return
print('该联系人不存在,请查证!')
telbook = {}
print('Here is Telbook System, choose a option to start!')
while 1:
choice = input('1、新建联系人\n2、删除联系人\n3、修改联系人电话号码信息\n4、查询联系人电话信息\n5、显示已有所有联系人及电话号码信息\n0、退出系统\nChoose: ')
if int(choice) == 1:
insert()
elif int(choice) == 2:
delete()
elif int(choice) == 3:
change()
elif int(choice) == 4:
search()
elif int(choice) == 5:
show_all()
elif int(choice) == 0:
exit(1)
else:
print('请输入正确选项序号!')
print('\n')