-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontact.py
78 lines (69 loc) · 2.33 KB
/
contact.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
#Contact Management System
contacts = {}
def menu():
print("\n Contact Management System Menu:")
print("1. Add a new contact")
print("2. Delete a contact")
print("3. Update a contact")
print("4. Search for a contact")
print("5. Display all contacts")
print("6. Exit")
def addContact():
name = input("Enter Name of the contact: ")
phone = input("Enter phone of the contact: ")
email = input("Enter email of the contact: ")
contacts[name] = {'phone' : phone, 'email' : email}
print(f"Succcessfully added {name} as contact")
def delContact():
name = input("Enter the name of the contact for deletion: ")
if name in contacts:
del contacts[name]
print(f"Succcessfully deleted {name} from contact")
else:
print("Contact Not Found")
def upContact():
name = input("Enter the name of the contact to Update: ")
if name in contacts:
phone = input("Enter new number for the contact(Leave this empty for current): ")
email = input("Enter new email for the contact(Leave this empty for current): ")
if phone:
contacts[name]['phone'] = phone
if email:
contacts[name]['email'] = email
print("Succcessfully updated the Contact from contact")
else:
print(f"Contact {name} not found")
def searchContact():
name = input("Enter name to search: ")
if name in contacts:
print(f"Contact {name} found")
print(f"phone: {contacts[name]['phone']} ")
print(f"email: {contacts[name]['email']} ")
else:
print("Contact Not Found")
def displayContact():
print("Displaying all the Contacts")
if contacts:
for name in contacts:
print(f"name: {name} phone: {contacts[name]['phone']} email: {contacts[name]['email']}")
else:
print("Contact Not Found in the list")
def main():
while True:
menu()
choice = input("Enter number (1-6): ")
if choice == '1':
addContact()
if choice == '2':
delContact()
if choice == '3':
upContact()
if choice == '4':
searchContact()
if choice == '5':
displayContact()
if choice == '6':
print("Exiting the Contact Management System")
break
if __name__ == "__main__":
main()