How to make your own contact book application using python

So here we are going to learn how we can make our contact book application using python. 

I will give a detailed explanation of each line.

So now we will see the code and understand each line of that

Contact_book = {}

while True:

   choice = input(“Please select one [X/A/S/P] \n X –> EXIT  \n A ==> ALL numbers \n S ==> SAVE \n P==> SEARCH the number  “).upper()

   if choice == “S”:

       person_name = input(“Please enter the person name”)

       mobile_number = input(“Please enter the mobile number”)

       Contact_book[person_name] = mobile_number

   elif choice == “P”:

       search_name = input(“Enter the name of person”)

       print(“So the number of “,search_name, “is”,Contact_book[search_name] )

   elif choice == “A”:


   elif choice == “X”:


Here Contact_book is a empty dictionary which will store value in key value pair, where key will be name and value will be mobile number.

In the next line i have used while loop which will run infinite time until we are not going to stop the execution. 

Line no 3. We have created one choice  variable where user will select the one option 

And after that we have used if elif for the condition, According to the condition it will execute the particular statement

Now first we will see what S is doing

In S statement it will save the value which will be person_name and mobile_number and store it into dictionary

In P we are going to search any number so we are going to take the name as key so we will pass that key in dictionary and fetch the value of that key which will be the mobile number

In A we will print the Dictionary which will be the whole contact book details

In X we will break the execution of program

Full code:


Also checkout the video tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *