-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.py
43 lines (42 loc) · 1.47 KB
/
contact.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
contacts = {}
while True:
print("""
Contact Management
1_ Add a contact
2_ View contact
3_ Edit a contact
4_ Exit
""")
choice = int(input("Please choose a number from 1-4 "))
if choice == 1:
contact_ID = input("Enter the contact ID: ")
contact_name = input("Please type a name: ")
contact_phone = input("Please type a phone number: ")
while True :
if contact_phone.isdigit():
break
else :
contact_phone = input("Please enter a number as digits: ")
contacts[contact_ID] = {"name":contact_name, "phone":contact_phone}
print(f"\n\n{contact_name} was added successfully..")
elif choice == 2 :
print(contacts)
elif choice == 3 :
id_to_edit = input("Please enter an ID edit: ")
if id_to_edit in contacts:
new_name = input("Enter a new name: ")
new_phone = input("enter a new number: ")
while True :
if new_phone.isdigit():
break
else :
new_phone = input("Please enter a number as digits: ")
contacts[id_to_edit] = {"name":new_name ,"phone":new_phone}
print("Success ...")
else:
print(f"Sorry, {id_to_edit} was not found ....")
elif choice == 4:
print("\n Exiting the program ....\n")
break
else :
print("invalide choice.")