-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
64 lines (57 loc) · 2 KB
/
app.py
File metadata and controls
64 lines (57 loc) · 2 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
import pprint
def menu():
options = [
"0. Add a contact",
"1. Search contact",
"2. Delete a contact",
"3. View all contacts",
"4. Quit",
]
for option in options:
print(option)
def main():
contacts = {"John": "1342343232", "Sara": "9876543210"}
while True:
menu()
choice = int(input("Enter option number: "))
if choice >= 0 and choice <= 4:
if choice == 0:
while True:
name = input("Enter name for the new contact: ")
if name == "q":
break
if name in contacts:
print("A contact with that name already exists!")
continue
phone_number = input("Enter a phone number: ")
contacts[name.lower()] = phone_number
print("Contact added!")
break
elif choice == 1:
while True:
search_query = input("Search: ")
if search_query == "q":
break
if search_query.lower() in contacts:
print(pprint.pformat(contacts[search_query.lower()]))
break
print("No contact with that name exists!")
continue
elif choice == 2:
while True:
name = input("Enter name for the new contact: ").lower()
if name == "q":
break
if name in contacts:
del contacts[name]
print("Contact deleted!")
break
print("No contact with that name exists!")
continue
elif choice == 3:
print(pprint.pformat(contacts))
elif choice == 4:
exit()
else:
continue
main()