Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python Part 2: Programming Problem Problem 1: Phone Book Implement simple phonebook operations. Phonebook is a dictionary with names as keys and phone numbers

in python

image text in transcribedimage text in transcribedimage text in transcribed

Part 2: Programming Problem Problem 1: Phone Book Implement simple phonebook operations. Phonebook is a dictionary with names as keys and phone numbers as values. A valid phone number is a string with 10 digits. For example: 2014567890' is a valid phone number. But '201a45b789' or '20145678' are both invalid. Your program should have the following functions: function add_entry(phonebook, name, phone number) that adds an entry to a phonebook. This function should take a dictionary as phonebook, a string name and a string phone_number as arguments. It then adds an entry with key name and value phone_number to phonebook given that the following is true: A An entry in phonebook with key name does not exist Phone_number is a valid phone number Your function should display an error message if the entry cannot be added. You might want to write a helper function to check if phone_number is valid A function lookup(phonebook, name) looks up phonebook. This function should return the phone number associated with name in phonebook. If the input name is not found in phonebook, display an error message that indicates so. A function print_all(phonebook) that prints all the entries in phonebook. Your function should print both the name and the phone number. A main function that opens 'Lab 13 -phonebook.txt in which each line has name and phone number. The names are in the form 'Last, Fist' (Note: some of the phone numbers could be in a bad format and some of the names could be duplicated). Use your function add_entry(phonebook, name, phone number) to construct a phonebook from entries in 'Lab 13 phonebook.txt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

What is Constitution, Political System and Public Policy? In India

Answered: 1 week ago

Question

What is Environment and Ecology? Explain with examples

Answered: 1 week ago

Question

Be familiar with the different perspectives of service quality.

Answered: 1 week ago

Question

Describe key customer feedback collection tools.

Answered: 1 week ago

Question

Know what customers expect from the firm when they complain.

Answered: 1 week ago