-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContactKeeper.py
55 lines (52 loc) · 1.79 KB
/
ContactKeeper.py
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
def insert(contacts) :
while(1):
a = input("Enter name (type exit to exit the insert mode) :")
if a == 'exit' :
break
b = input("Enter contact number :")
contacts[a] = b
contacts = sorted(contacts.items())
contacts = {x:y for x,y in contacts}
return contacts
def key_search(contacts) :
count = 0
names = {}
while(1) :
key = input("Enter the keyword to be searched (type exit to exit this mode) :")
if key == 'exit' :
break
for name in contacts.keys() :
if key in name :
names[count] = name
count += 1
if count == 0 :
print("Error!!!! This keyword does not exist")
if count == 1 :
print("Name : " + str(names[0]))
print("Contact Number : " + str(contacts[names[0]]))
if count > 1 :
for i in range(count) :
print(str(i) + " : " + str(names[i]))
name = input("Choose the desired name(type the index before the name) : ")
print("Contact Number : " + str(contacts[names[int(name)]]))
names.clear()
count = 0
def switch(contacts) :
while(1) :
arg = input("Enter a query : ")
if arg == '1' :
contacts = insert(contacts)
elif arg == '2' :
key_search(contacts)
elif arg == '3' :
print(contacts)
else :
break
return contacts
contacts = {}
print("Query List :")
print("1 : Insert a new contact")
print("2 : Retrieve details about a contact")
print("3 : Print the contact list (shows that contacts are always stored in dictionary order)")
print("Enter anything else to exit")
contacts = switch(contacts)