-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask5_CONTACT BOOK.py
119 lines (97 loc) · 4.22 KB
/
Task5_CONTACT BOOK.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
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
def AddContact(details):
name = input("Enter the name: ")
phone_no = int(input("Enter the phone number: "))
email = input("Enter the email: ")
address = input("Enter the address: ")
details[name]={"Phone_no":phone_no , "Email": email , "Address": address}
return details
def ViewContact(details):
for names in details:
print(names, details[names]["Phone_no"], end="\n")
def SearchContact(details, name="NULL", phone_no = 0):
if name!="NULL" and phone_no==0:
for names in details:
if names == name:
return (names,details[names])
return ("No such Contact exits")
elif name=="NULL" and phone_no!=0:
for names in details:
if details[names]["Phone_no"]==phone_no:
return (names,details[names])
return ("No such Contact exits")
else:
for names in details:
if details[names]["Phone_no"]==phone_no and names == name :
return (names,details[names])
return ("No such Contact exits")
def UpdateContact(details):
ch = input("Want to update contact name (Y/N)")
if ch.upper() =="Y":
old_name = input("Enter the old name: ")
new_name = input("Enter the updated name: ")
item = details[old_name]
del details[old_name]
details[new_name]=item
ch = input("Want to update Phone number (Y/N)")
if ch.upper()=="Y":
name = input("Enter the name of the Contact: ")
new_phone_no = int(input("Enter the updated phone number: "))
details[name]["Phone_no"] = new_phone_no
ch = input("Want to update email (Y/N)")
if ch.upper() == "Y":
name = input("Enter the name of the Contact: ")
new_email = input("Enter the updated email: ")
details[name]["Email"] = new_email
ch = input("Want to update address (Y/N)")
if ch.upper() == "Y":
name = input("Enter the name of the Contact: ")
new_address = input("Enter the updated address: ")
details[name]["Address"] = new_address
return details
def DeleteContact(details):
ch = input("Want to delete the Contact by Name (N) or Phone number (P): ")
if ch.upper() =="N":
name = input("Enter the Name of the contact to delete: ")
del details[name]
elif ch.upper() == "P":
phone_no = int(input("Enter the Phone number of the contact to delete: "))
for names in details:
if details[names]["Phone_no"]==phone_no :
del details[names]
break
return details
print("\t--------------------CONTACT BOOK--------------------\n")
details = {"Sachin":{"Phone_no":7864678898, "Email":"sachin123@gamil.com", "Address":"Colen,UK"},
"Naveen":{"Phone_no":9167345698, "Email":"navven778@gamil.com", "Address":"Burlington, UP"},
"John":{"Phone_no":8967345687, "Email":"john657332@gamil.com", "Address":"Mohbillapur, USA"}}
while True:
print("\nFor Adding new contact , -------------press 1")
print("For Viewing contact list , -----------press 2")
print("For Updating the contacts ,---------- press 3")
print("For Searching the contact ,---------- press 4")
print("For Deleting contact ,--------------- press 5")
print("For exiting the Contact book, --------press 6\n")
choice = int(input("Enter the choice: "))
if choice == 1:
details = AddContact(details)
elif choice == 2:
ViewContact(details)
elif choice == 3:
details = UpdateContact(details)
elif choice == 4:
name = input("Enter the name of the contact to search otherwise enter null: ")
phone_no = int(input("Enter the phone number to search otherwise enter 0: "))
if name == "null":
search = SearchContact(details, phone_no)
elif phone_no==0:
search = SearchContact(details, name)
else:
search = SearchContact(details, name, phone_no)
print(search)
elif choice == 5:
details = DeleteContact(details)
elif choice == 6:
print("Exiting the Contact Book :)")
break
else:
print("Wrong input")