-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjective7ContactBook.py
71 lines (63 loc) · 2.25 KB
/
objective7ContactBook.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
class Contact:
def __init__(self, name, phone, email):
self.name = name
self.phone = phone
self.email = email
def __str__(self):
return f"Name: {self.name}, Phone: {self.phone}, Email: {self.email}"
class ContactBook:
def __init__(self):
self.contacts = []
def add_contact(self):
name = input("Enter contact name: ")
phone = input("Enter contact phone number: ")
email = input("Enter contact email: ")
contact = Contact(name, phone, email)
self.contacts.append(contact)
print(f"Contact {name} added successfully.")
def delete_contact(self):
name = input("Enter the name of the contact to delete: ")
for contact in self.contacts:
if contact.name.lower() == name.lower():
self.contacts.remove(contact)
print(f"Contact {name} deleted successfully.")
return
print(f"Contact {name} not found.")
def search_contact(self):
name = input("Enter the name of the contact to search: ")
for contact in self.contacts:
if contact.name.lower() == name.lower():
print(contact)
return
print(f"Contact {name} not found.")
def view_contacts(self):
if not self.contacts:
print("No contacts available.")
else:
for contact in self.contacts:
print(contact)
def main():
contact_book = ContactBook()
while True:
print("\nContact Book")
print("1. Add Contact")
print("2. Delete Contact")
print("3. Search Contact")
print("4. View All Contacts")
print("5. Exit")
choice = input("Choose an option: ").strip()
if choice == "1":
contact_book.add_contact()
elif choice == "2":
contact_book.delete_contact()
elif choice == "3":
contact_book.search_contact()
elif choice == "4":
contact_book.view_contacts()
elif choice == "5":
print("Goodbye!")
break
else:
print("Invalid choice. Please choose again.")
if __name__ == "__main__":
main()