-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContact-Book.py
More file actions
78 lines (62 loc) · 2.46 KB
/
Contact-Book.py
File metadata and controls
78 lines (62 loc) · 2.46 KB
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
class Contact:
def __init__(self, name, phone, email, address):
self.name = name
self.phone = phone
self.email = email
self.address = address
class ContactManager:
def __init__(self):
self.contacts = {}
def add_contact(self, name, phone, email, address):
self.contacts[name] = Contact(name, phone, email, address)
def view_contacts(self):
for name, contact in self.contacts.items():
print(f"Name: {contact.name}, Phone: {contact.phone}, Email: {contact.email}, Address: {contact.address}")
def search_contact(self, query):
for name, contact in self.contacts.items():
if query in name or query in contact.phone:
print(f"Name: {contact.name}, Phone: {contact.phone}, Email: {contact.email}, Address: {contact.address}")
def update_contact(self, name, phone, email, address):
if name in self.contacts:
self.contacts[name] = Contact(name, phone, email, address)
else:
print("Contact not found")
def delete_contact(self, name):
if name in self.contacts:
del self.contacts[name]
else:
print("Contact not found")
if __name__ == "__main__":
cm = ContactManager()
while True:
print("1. Add Contact")
print("2. View Contact List")
print("3. Search Contact")
print("4. Update Contact")
print("5. Delete Contact")
print("6. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
name = input("Enter name: ")
phone = input("Enter phone: ")
email = input("Enter email: ")
address = input("Enter address: ")
cm.add_contact(name, phone, email, address)
elif choice == 2:
cm.view_contacts()
elif choice == 3:
query = input("Enter search query: ")
cm.search_contact(query)
elif choice == 4:
name = input("Enter name: ")
phone = input("Enter new phone: ")
email = input("Enter new email: ")
address = input("Enter new address: ")
cm.update_contact(name, phone, email, address)
elif choice == 5:
name = input("Enter name: ")
cm.delete_contact(name)
elif choice == 6:
break
else:
print("Invalid choice")