import string class ContactInfo: # Create initializer def __init__ (self, street, city, state, zip, country, phone, email): # Define global dictionary to hold all the contact information phoneBook = {} # This function adds the contact information of a new person in the # dictionary def addPerson(): # Prompt the user to enter the name of the new person # Check if name exists in phone book. If it does print a message # to that effect and return # Prompt the user to enter the required contact information # Create the ContactInfo object contactObj = ContactInfo (street, city, state, zip, country, phone, email) # Add the name and the contact information to the phone dictionary # Print message that the information was added successfully # This function deletes an existing person from the phone dictionary def deletePerson(): # Prompt the user to enter the name of the person # If the name exists in phone book delete it. # Print message as to the action. # This function updates the information of an existing person def updatePerson(): # Prompt the user to enter the name of the person # Check if name exists in phone book. If it does prompt # the user to enter the required information. # Write a message as to the action # This function prints the contact information of an existing person def searchPerson(): # Prompt the user to enter the name of the person # Check if name exists in phone book. If it does print the # information in a neat format. # If the name does not exist print a message to that effect. # This function open the file for writing and writes out the contents # of the dictionary. def saveQuit(): # Open file for writing # Iterate through the dictionary and write out the items in the file # Close file # Print message # This function prints the menu, prompts the user for his/her selection # and returns it. def menu(): # This function opens the file for reading, reads the contact information # for each person and adds it to the dictionary. def createPhoneBook(): # Open file for reading # Read first line (name) line = infile.readline() # Loop through the entries for each person while (line != ""): # Read street # Read city # Read state # Read zip # Read country # Read phone # Read e-mail address # Read blank line # Read first line of the next block of data line = infile.readline() # Create ContactInfo object # Add to phone dictionary # Close file def main(): # Read file and create phone book dictionary createPhoneBook() # Print logo print "Phone Book" # Print menu and get selection selection = menu() # Keep track of changes in the dictionary numChanges = 0 # Process request, print menu and prompt again and again # until the user types 5 to quit. # Save and quit # Goodbye message print print "Thank you for using the Phone Book.\n" main()