-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneBook.py
More file actions
53 lines (53 loc) · 1.73 KB
/
Copy pathPhoneBook.py
File metadata and controls
53 lines (53 loc) · 1.73 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
def main():
phone_record={}
while True:
print('''1. Add a new phone number
2. Delete a phone number
3. Up date a phone number
4. Search a phone number
5. Display all phone numbers
6. Quit''')
choice=int(input('Enter your choice: '))
if choice ==6:
break
elif choice==1:
add_contact(input('Enter name: '),input('Enter number: '),phone_record)
elif choice==2:
delete_contact(input('Enter name: '),phone_record)
elif choice==3:
update_contact(input('Enter name: '),input('Enter number: '),phone_record)
elif choice==4:
search_contact(input('Enter name: '),phone_record)
elif choice==5:
display_all(phone_record)
else:
print('Invalid choice')
def add_contact(name,number,phone_record):
if (name in phone_record):
print('Contact already exists with this name')
else:
phone_record[name]=number
print('Contact added successfully')
def delete_contact(name,phone_record):
if name in phone_record:
del phone_record[name]
print('Contact deleted successfully')
else:
print('Contact not found')
def update_contact(name,number,phone_record):
if name in phone_record:
phone_record[name]=number
print('Contact updated successfully')
else:
print('Contact not found')
def search_contact(name,phone_record):
if name in phone_record:
print('Contact found')
print('Name: ',name,'Number: ',phone_record[name])
else:
print('Contact not found')
def display_all(phone_record):
for name,number in phone_record.items():
print('Name: ',name,'Number: ',number)
if __name__=='__main__':
main()