Question: Write a program in python that repeatedly displays menu: My Phonebook 1. Find a phone number by name. 2. Add an entry. 3. Quit. Your

Write a program in python that repeatedly displays menu:

My Phonebook

1. Find a phone number by name.

2. Add an entry.

3. Quit.

Your choice:

If the user chooses 1, there will be prompt for the name, and either the program will display the corresponding phone number or tell that there is no such an entry.

If the user chooses 2, there will be a prompt for the name, and the program will either follow with a prompt for the phone number or tell that there is already an entry for that name.

When the user enters option from the main menu, guarding against errors of input must be used. Use $csc223/01guarding/guarding.py.

When the program is running the phone book data must be stored in a dictionary, and between the sessions (when it is not running) it must be stored in a file phonebook.dat by using the module pickle.

The project must be in a directory 01phonebook and must contain files guarding.py (given to you), phonebook.py and phonebook.dat. The .py files must have the shebang line on the top: #!//usr/bin/env python3 and they must be made executable (by the linux shell command chmod u+x.

Module guarding.py Contains functions to get standard input while guarding agains errors: getInteger(prompt) getIntegerBetween(prompt, lower, upper) To use this module, copy it to your project directory and place an import statement in your program. Import only your copy of the module, not the orginal from $csc221 -- the original is likely to be modified. To do: write functions, which prompt for an abritrary number (float or int). '''

def getInteger(prompt): while True: try: n = int(input(prompt)) break except ValueError: print("This input is not correct. Try again ...") return n

def getIntegerBetween0(prompt, lower, upper): '''getIntegerBetween0(prompt, lower, upper) getIntegerBetween0(, , ) prompts the user, enforces that the input is an integer lower..upper (including lower and upper) and returns the input integer. Notice that the allowed inputs include upper -- this is different than the convention for range(lower, upper). ''' while True: try: n = int(input(prompt)) if lower <= n <= upper: break else: raise ValueError except ValueError: print("This input is not correct. Try again ...") return n

def getIntegerBetween(prompt, lower = None, upper = None): '''getIntegerBetween(prompt, lower, upper) getIntegerBetween(, , ) prompts the user, enforces that the input is an integer lower..upper (including lower and upper) and returns the input integer. Notice that the allowed inputs include upper -- this is different than the convention for range(lower, upper). If lower is None, arbitrarily small integer inputs are accpted. If upper is None, arbitrarily big integer inputs are accepted. ''' while True: try: n = int(input(prompt)) lower0 = lower if lower != None else n upper0 = upper if upper != None else n if lower0 <= n <= upper0: break else: raise ValueError except ValueError: print("This input is not correct. Try again ...")

return nWrite a program that repeatedly displays menu:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!