-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask5.py
More file actions
92 lines (82 loc) · 3.07 KB
/
task5.py
File metadata and controls
92 lines (82 loc) · 3.07 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Contact Management System in Python
contacts = [] # List to store contacts
def add_contact():
name = input("Enter Name: ")
phone = input("Enter Phone Number: ")
email = input("Enter Email: ")
address = input("Enter Address: ")
contact = {
"name": name,
"phone": phone,
"email": email,
"address": address
}
contacts.append(contact)
print("✅ Contact added successfully!\n")
def view_contacts():
if not contacts:
print("No contacts found.\n")
return
print("\n📒 Contact List:")
for i, contact in enumerate(contacts, 1):
print(f"{i}. {contact['name']} - {contact['phone']}")
print()
def search_contact():
keyword = input("Enter name or phone number to search: ")
found = False
for contact in contacts:
if keyword.lower() in contact['name'].lower() or keyword in contact['phone']:
print("\n🔍 Contact Found:")
print(f"Name: {contact['name']}")
print(f"Phone: {contact['phone']}")
print(f"Email: {contact['email']}")
print(f"Address: {contact['address']}\n")
found = True
if not found:
print("❌ No matching contact found.\n")
def update_contact():
search_name = input("Enter the name of the contact to update: ")
for contact in contacts:
if contact['name'].lower() == search_name.lower():
print("Leave field blank to keep current value.")
contact['phone'] = input(f"New Phone ({contact['phone']}): ") or contact['phone']
contact['email'] = input(f"New Email ({contact['email']}): ") or contact['email']
contact['address'] = input(f"New Address ({contact['address']}): ") or contact['address']
print("✅ Contact updated successfully!\n")
return
print("❌ Contact not found.\n")
def delete_contact():
search_name = input("Enter the name of the contact to delete: ")
for contact in contacts:
if contact['name'].lower() == search_name.lower():
contacts.remove(contact)
print("🗑️ Contact deleted successfully!\n")
return
print("❌ Contact not found.\n")
def menu():
while True:
print("====== 📱 Contact Management System ======")
print("1. Add Contact")
print("2. View Contacts")
print("3. Search Contact")
print("4. Update Contact")
print("5. Delete Contact")
print("6. Exit")
choice = input("Enter your choice (1-6): ")
if choice == "1":
add_contact()
elif choice == "2":
view_contacts()
elif choice == "3":
search_contact()
elif choice == "4":
update_contact()
elif choice == "5":
delete_contact()
elif choice == "6":
print("👋 Exiting... Goodbye!")
break
else:
print("❌ Invalid choice. Please try again.\n")
# Run the program
menu()