-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphonebook.py
63 lines (49 loc) · 1.46 KB
/
phonebook.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
56
57
58
59
60
61
62
63
import hashlib as hsh
phonebook = {}
def hashthat(name):
hashvalue = hsh.md5(name.encode())
hashed = hashvalue.hexdigest()
return hashed
def addContact(name, num):
h = hashthat(name)
phonebook[h] = {}
phonebook[h]['name'] = name
phonebook[h]['number'] = num
print('Successfully saved contact!')
def findContact(name):
h = hashthat(name)
if h in phonebook:
print(phonebook[h])
else:
print('No such contact in the phone book')
def removeContact(name):
h = hashthat(name)
if h in phonebook:
del phonebook[h]
print('Successfully deleted contact')
else:
print('No such contact in directory')
def showBook():
print('Name \t Contact')
for k in phonebook:
print(phonebook[k]['name'], '\t', phonebook[k]['number'])
run = True
while run:
print("Options: 'add' -> Add Contact \n 'find' -> Find Contact \n 'remove' > Remove Contact \n 'show' -> print phone book \n 'exit' -> Exit Phone Book ")
a = input('Please choose option')
if a == 'add':
name = input("Enter Contact Name: ")
num = input("Enter Phone Number: ")
addContact(name, num)
elif a == 'find':
name = input("Enter Contact Name: ")
findContact(name)
elif a == 'remove':
name = input("Enter Contact Name: ")
removeContact(name)
elif a == 'show':
showBook()
elif a == 'exit':
run = False
else:
print('Wrong input')