-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontactapp.py
More file actions
47 lines (40 loc) · 1.21 KB
/
contactapp.py
File metadata and controls
47 lines (40 loc) · 1.21 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
contacts = []
def add_contact():
name = input("Enter contact name: ")
phone = input("Enter phone number: ")
contact = {"name": name, "phone": phone}
contacts.append(contact)
print("Contact added!")
def view_contacts():
if not contacts:
print("No contacts found.")
else:
for contact in contacts:
print(f"Name: {contact["name"]}, Phone: {contact["phone"]}")
def search_contact():
search_name = input("Enter name to search: ")
found = False
for contact in contacts:
if contact["name"].lower() == search_name.lower():
print(f'Found - Name: {contact["name"]}, Phone: {contact["phone"]}')
found = True
if not found:
print("Contact not found.")
while True:
print("1. Add Contact")
print("2. View Contacts")
print("3. Search Contact")
print("4. Exit")
choice = input("select your choice 1-4: ")
if choice == "1":
add_contact()
elif choice == "2":
view_contacts()
elif choice == "3":
search_contact()
elif choice == "4":
print("Goodbye")
break
else:
print("Invalid input")
print(contacts)