-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontacttlist.py
More file actions
70 lines (62 loc) · 2.35 KB
/
contacttlist.py
File metadata and controls
70 lines (62 loc) · 2.35 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
contacts = { }
def menu():
print("--------------------MENU----------------------")
print("press 4 if you want to terminate program.")
print("press 0 to look up an existing number.")
print("press 1 to add a Person to the contact book.")
print("press 2 to update an existing number")
print("press 3 to delete an existing number")
print("press 5 to print all contacts")
print("press any number from 6-9 to display Menu")
print("----------------------------------------------")
print(" DIGITAL CONTACT BOOK ")
menu()
def display():
for key, value1 in contacts.items():
print(key, ":", value1)
while True:
choice = int(input("Enter command:"))
if choice == 0:
look = input("Name of number owner:").upper()
keys = list(contacts.keys())
values1 = list(contacts.values())
print("Number of ", look, ":", values1[keys.index(look)])
elif choice == 1:
Name = input("Name of new contact: ").upper()
Number = input("Enter 11 or 8 digit number: ")
if len(Number) == 11:
contacts.update({Name: [Number, "Mobile"]})
print(" CONTACTS")
display()
elif len(Number) == 8:
contacts.update({Name:[Number, "Landline"]})
print(" CONTACTS")
display()
else:
print("Number is invalid.Please try again.")
elif choice == 2:
Name = input("Name of person to update contact:").upper()
Number = input("New contact number( 11 or 8 digits):")
if len(Number) == 11:
contacts[Name] = [Number, "Mobile"]
print(" CONTACTS")
display()
elif len(Number) == 8:
contacts[Name] = [Number, "Landline"]
print(" CONTACTS")
display()
else:
print("Number is invalid.Please try again.")
elif choice == 3:
delete = input("Name of contact to remove:").upper()
del contacts[delete]
print(" CONTACTS")
display()
elif choice == 4:
print("Thank you for using the Digital Contact Book!")
break
elif choice == 5:
print(" CONTACTS")
display()
else:
menu()