Question: Use Python 3 to write this code The purpose of this assignment is to build a phone book that will store contact information of people
Use Python 3 to write this code
The purpose of this assignment is to build a phone book that will store contact information of people that you know. The contact information will be the address, phone number, and e-mail address. In this phone book you can add, delete, lookup, and update information about a person using their name as the key. The data structure that you will be using will be a dictionary.
All the names of the people and their contact information will be stored in a file called phone.txt. Each person will have the following pieces of information associated with him or her:
name
street
city
state
zip
country
phone number
e-mail address
Each piece of information (i.e. name, street, etc.) will be stored in the file on separate lines. There will be a blank line at the end of the contact information of each person.
This program is menu driven. When the program is initiated, a function opens the file phone.txt reads the data from the file creates a ContactInfo object and stores that object as the value in a dictionary where the name of the person is the key. The menu choices are:
add a person
delete a person
search for a person
update the information of a person
save and quit the program
The opening screen for the phone book will appear as shown below:
Phone Book 1. Add a Person 2. Delete a Person 3. Search for a Person 4. Update Information on a Person 5. Quit Enter your selection:
The user will make a menu selection by typing a number between 1 and 5. If the user selects a number other than a number in that range then you will state that it is an invalid selection and ask the user to select again. You will keep prompting until the user either makes a valid selection or quits.
Each valid selection will be handled by a separate function. After your program has handled menu items 1 through 4, the same menu should reappear for additional requests by the user. The handling of each menu item is explained in detail below. When the user selects menu item 5, the appropriate function is called and then the program prints a message thanking the user.
Thank you for using the phone book.
1. Add a Person: This function will prompt the user to enter the following data:
Enter name: Enter street: Enter city: Enter state: Enter zip: Enter country: Enter phone number: Enter e-mail address:
You will create a ContactInfo object and add that to the dictionary with the name as key. Here are special cases that you need to consider:
If the name already exists, alert the user and return from the function.
If the name is not entered, do nothing.
If any other data item is not entered, create the ContactInfo object with a blank string for that field.
2. Delete a Person: Prompt the user to enter the name.
Enter name:
If the name exists, delete the the person from the dictionary. Write a message to that effect.
So-and-So was deleted from the phone book.
If the name does not exist write a message to that effect.
So-and-So does not exist in the phone book.
3. Search for a Person: Prompt the user to enter the name.
Enter name:
If the name exists, write the name and the contact information in a neat format. If the name does not exist write a message to that effect.
So-and-So does not exist in the phone book.
4. Update Information on a Person: This function will prompt the user to enter the information below. The user should enter a valid name and any other piece or pieces of information that he wants to update. He may choose not to enter any data field that has not changed. For example, if only the e-mail address has changed for a person, then the user will enter only the name and the e-mail address and leave everything blank.
Enter name: Enter street: Enter city: Enter state: Enter zip: Enter country: Enter phone number: Enter e-mail address:
If the name exists, retrieve the ContactInfo object from the dictionary for that person. For those fields that are not blank change it in the ContactInfo object and store it back in the dictionary. If the name does not exist, write a message to that effect.
So-and-So does not exist in the phone book.
5. Quit: In this function, you will open the file phone.txt for writing (not appending). You will write out all the key-value pairs in the file in exactly the same format that you read the data in. You will close the file after writing.
Before you turn your assignment in, you must thoroughly test each of the functionality. Here is a list of tests that you must perform and your program should pass each test.
Add at least 2 people to your phone book.
Quit and restart the program.
Search for a person that you just added. Your program should print out the information on that person.
Search for a person you know is not in the phone book. Your program should print out that that person was not found.
Update the information of a person in the phone book.
Search for the same person in the phone book so that you can see that the information has been correctly updated.
Delete a person that you know is there from the phone book.
Search for that person and the program should print out that that person could not be found.
Please help me with this programming in Python 3. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
