Python programming language is used to create a list of contacts . Dictionaries’ are used to store the names and contact details of people . Dictionary is the most preferred choice because it follows the method of keys and values i.e it assigns a key for every value stored in it . In case of a phonebook , the keys reassemble the contacts name and the value equates with the phone number.
Table of Contents
Source code to implementing contact book / address using python
Below are source code available please run this code in python IDE
contact_list={}
flag=True
def addContact(key,val):
if key not in contact_list:
contact_list[key]=val
else:
print("Already Existing")
def deleteContact(key):
if key in contact_list:
contact_list.pop(key)
else:
print("Contact not found")
def searchContact(key):
if key in contact_list:
print(key,contact_list[key])
else:
print("Contact not found")
def modifyName(key):
if key in contact_list:
name=input("Enter the name you want it to be saved")
contact_list[name]=contact_list[key]
del contact_list[key]
else:
print("Contact not found")
def modifyNo(key):
if key in contact_list:
no=int(input("Enter modified mobile no"))
contact_list[key]=no
else:
print("Contact not found")
def displayContacts():
for key,val in contact_list.items():
print(key,val)
while(flag):
print()
print("1.Add Contact 2.Delete Contact 3.Search Contact 4.Modify Contact 5.Display Conatacts
6.Exit")
ch=int(input("Enter your choice"))
if(ch==1):
key=input("Enter name")
val=int(input("Enter mobile no"))
addContact(key,val)
elif(ch==2):
key=input("Enter contact name to be deleted")
deleteContact(key)
elif(ch==3):
key=input("Enter the contact name to be searched")
searchContact(key)
elif(ch==4):
key=input("Enter contact name to be modified")
print("1.To change the name of existing contact 2.To change mobile no")
c=int(input())
if(c==1):
modifyName(key)
elif(c==2):
modifyNo(key)
else:
print("Wrong choice")
elif(ch==5):
displayContacts()
elif(ch==6):
flag=False;
else:
print("Wrong Choice")
Output windows for implementing contact book / address using python
this is a final output windows which shown after the run above code
Summary :
In this article we saw how to create and implementing contact book / address using python so about this article yo have any query then free to ask me