-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContactBook.py
46 lines (42 loc) · 1.55 KB
/
ContactBook.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
contact={}
def display_contact():
print("Name\n\nContact number")
for key in contact:
print("{}\n\n{}".format(key,contact.get(key)))
while True:
choice=int(input("1.Add new contact\n 2.Search contact\n 3.Display contact\n 4.Edit contact\n 5.Delete contact\n 6.Exit\n\n"))
if choice==1:
name=input("enter the contact name: ")
phone=input("enter the mobile number: ")
contact[name]=phone
elif choice==2:
search_name=input("enter the contact name")
if search_name in contact:
print(search_name," 's contact number is ",contact[search_name])
else:
print("Name is not found in contact book")
elif choice==3:
if not contact:
print("empty contact book")
else:
display_contact()
elif choice==4:
edit_contact=input("Enter the contact to be edited:")
if edit_contact in contact:
phone=input("enter mobile number")
contact[edit_contact]=phone
print("contact updated")
display_contact()
else:
print("Name is not found in conatct book")
elif choice==5:
del_contact=input("Enter the contact to be deleted" )
if del_contact in contact:
confirm=input("Do you want to del this contact y/n?")
if confirm=='y' or confirm =='Y':
contact.pop(del_contact)
display_contact()
else:
print("Conatct not found")
else:
break