By Papri Boyra
This code initializes an empty dictionary called contacts Books for storing contact information.
This Python program utilizes a dictionary named "contacts" to hold contact details, with contact names serving as keys and phone numbers as values. It can efficiently store and retrieve the contact information required by its users. The usage of dictionaries for data storage is a common practice in Python as it can help organize similar information and facilitate easy access.
The add_contact function allows for easy addition of contacts to the contacts dictionary. Users can input a contact name and phone number, which are then added to the dictionary as the key and value respectively. Once added, a confirmation message is printed to let the user know that their contact has been successfully added. This function streamlines the process of adding new contacts to the dictionary, and makes it simple for users to keep track of their contacts in one place.
The view_contacts function displays all contacts saved in the dictionary. It prints out the name and phone number of each contact by iterating through the dictionary. If there are no contacts available in the dictionary, it will inform the user that no contacts were found.
The search_contact function is used to search for a contact by name. It takes the name of the contact as input and looks for it in the contacts dictionary. If the name is found, the function prints the contact's name and phone number. However, if the name is not found, an error message is displayed. This function helps users quickly find the phone number of a contact, making it easier to stay in touch.
The main loop of the program presents the user with a menu, providing four options to choose from - add a contact, view contacts, search for a contact, or exit the program. The user is prompted to input the corresponding number of the option they wish to choose. The program then carries out the selected operation accordingly. This user-friendly interface simplifies navigation through the program and enhances user experience by allowing them to perform their desired function with ease.
The program handles user choices by calling the corresponding function based on their choice. If an invalid option is chosen, the program prompts the user to try again. The functions available are adding a contact, viewing contacts, and searching for a contact. The program exits if the user chooses to do so.
Submitted by Papri Boyra (Boyra)
Download packets of source code on Coders Packet
Comments