So our curious minds are you ready to create a Phonebook using Python?
Hello, coders, welcome to the codewithrandom blog. Creating a phone book using Python is a great project for beginners looking to practice their coding skills. In this blog post, we will go through the steps of creating a phonebook program using Python.
Before we start coding, let’s define what a phonebook is?🤔
What is the need for a phonebook?
My friends have you ever thought that in coding storing important details like contact information, phone numbers, names, email IDs, etc is crucial, how can we do this was a topic of concern hence the idea of a data structure in Python was developed where we can store the important information easily.
What is a phonebook?
A phone book is a directory used to store and manage a list of names and phone numbers. In our program, we will create a phone book that allows users to add, search, and delete entries.
- Managing contacts becomes easy by using a phonebook in Python.
- You can easily search for the respective details you want to find.
Parking Management System Project Using Python
How to Create a Restaurant Management System Using Python
To Create a Phonebook using Python, we need to perform the following steps:
- open any Python code Editor.
- Copy the code for the Create a Phone Book Using Python, which I provided Below in this article, and save it in a file named “main.py” (or any other name you prefer).
- Run this main.py to start the phonebook.
Here complete Phonebook Python code is given👇👇
You can directly copy and paste it into your projects.
names = [] phone_numbers = [] num = 3 for i in range(num): name = input("Name: ") phone_number = input("Phone Number: ") # for convert to int => int(input("Phone Number: ")) names.append(name) phone_numbers.append(phone_number) print("\nName\t\t\tPhone Number\n") for i in range(num): print("{}\t\t\t{}".format(names[i], phone_numbers[i])) search_term = input("\nEnter search term: ") print("Search result:") if search_term in names: index = names.index(search_term) phone_number = phone_numbers[index] print("Name: {}, Phone Number: {}".format(search_term, phone_number)) else: print("Name Not Found")
Output 👇👇
Conclusion of the above code.
Hurray! You have successfully Created the Phone Book Using python. Python provides a simple and elegant way to create a phone book using the dictionary data structure. With the help of built-in functions and control structures, one can create a fully functional phone book application in Python. Hope you enjoyed building with us! Visit our homepage and you get lots of projects💝.
Some FAQ’s related to phone book python code :
1. What is a phonebook?
A phone book is a directory used to store and manage a list of names and phone numbers. In our program, we will create a phone book that allows users to add, search, and delete entries.
2. What is the need for a phonebook?
My friends have you ever thought that in coding storing important details like contact information, phone numbers, names, email IDs, etc is crucial, how can we do this was a topic of concern hence the idea of a data structure in Python was developed where we can store the important information easily.
3. How phonebook is helpful?
- Managing contacts becomes easy by using a phonebook in Python.
- You can easily search for the respective details you want to find.
4. How to add a phone number in the phonebook python code?
names = []
phone_numbers = []
num = 3
for i in range(num):
name = input(“Name: “)
phone_number = input(“Phone Number: “) # for convert to int => int(input(“Phone Number: “))
names.append(name)
ADVERTISEMENT
phone_numbers.append(phone_number)
ADVERTISEMENT
print(“\nName\t\t\tPhone Number\n”)
ADVERTISEMENT
ADVERTISEMENT
5. How to search for something?
ADVERTISEMENT
for i in range(num):
print(“{}\t\t\t{}”.format(names[i], phone_numbers[i]))
search_term = input(“\nEnter search term: “)
print(“Search result:”)
if search_term in names:
index = names.index(search_term)
phone_number = phone_numbers[index]
print(“Name: {}, Phone Number: {}”.format(search_term, phone_number))
else:
print(“Name Not Found”)
If you have any queries, you are free to ask in the comment section.
Keep learning!!
Thank you!!😁