Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Start by downloading a clean copy of the the restaurants program(I list below). The original program has a section for Restaurants and a section for

Start by downloading a clean copy of the the restaurants program(I list below). The original program has a section for Restaurants and a section for Collections. You'll want to add a section for Dishes and a section for Menus. In the Dish section, include the functions dish_str (which you already wrote) and dish_get_info, which works along the same lines as restaurant_get_info.

Now, in the Menus section, write a menu_enter function that repeatedly asks whether the user wants to add a Dish. If the user enters yes, the function prompts the user to create a Dish and adds it on to the growing list of dishes; when the user enters no, the function returns the compiled list of Dishes.

Now, where do we have to call menu_enter and take the Menu it returns, including it into the whole data structure in the appropriate place? In the Menus section, you'll also need something to create a display string for the menu of dishes; you'll also need to find where in the program to call the function that generates the Menu display string.

Next, incorporate your price-changing code into the program so that ultimately, the main menu gives the same option as above: c: Change prices for the dishes served When the user types c, the program should ask the user for an amount representing a percentage change in price, as before, and it should apply that price change to the prices for all the Dishes in all the Restaurants in the collection.

Here is the restaurant program:

##### MAIN PROGRAM (CONTROLLER) def restaurants():

# nothing -> interaction """ Main program """

print("Welcome to the restaurants program!")

our_rests = collection_new()

our_rests = handle_commands(our_rests)

print(" Thank you. Good-bye.")

MENU = """

Restaurant Collection Program --- Choose one

a: Add a new restaurant to the collection

r: Remove a restaurant from the collection

s: Search the collection for selected restaurants

p: Print all the restaurants

q: Quit """

def handle_commands(diners: list) -> list:

""" Display menu, accept and process commands. """

done = False while not done: response = input(MENU)

if response=="q": done = True return diners

elif response=='a': r = restaurant_get_info() diners = collection_add(diners, r)

elif response=='r': n = input("Please enter the name of the restaurant to remove: ") diners = collection_remove_by_name(diners, n)

elif response=='p': print(collection_str(diners))

elif response=='s': n = input("Please enter the name of the restaurant to search for: ") for r in collection_search_by_name(diners, n): print(restaurant_str(r)) else: invalid_command(response) def invalid_command(response): # string -> interaction """

Print message for invalid menu command. """ print("Sorry; '" + response + "' isn't a valid command. Please try again.")

##### Restaurant

from collections import namedtuple Restaurant = namedtuple('Restaurant', 'name cuisine phone dish price') # Constructor: r1 = Restaurant('Taillevent', 'French', '01-11-22-33-44', 'Escargots', 23.50)

def restaurant_str(self: Restaurant) -> str: r

eturn ( "Name: " + self.name + " " + "Cuisine: " + self.cuisine + " " + "Phone: " + self.phone + " " + "Dish: " + self.dish + " " + "Price: ${:2.2f}".format(self.price) + " ")

def restaurant_get_info() -> Restaurant: """ Prompt user for fields of Restaurant; create and return. """

return Restaurant( input("Please enter the restaurant's name: "), input("Please enter the kind of food served: "), input("Please enter the phone number: "), input("Please enter the name of the best dish: "), float(input("Please enter the price of that dish: ")))

#### COLLECTION # A collection is a list of restaurants def collection_new() -> list:

''' Return a new, empty collection '''

return [ ] def collection_str(diner_collection: list) -> str: '''

Return a string representing the collection '''

s = "" for r in diner_collection: s = s + restaurant_str(r)

return s def collection_search_by_name(diner_list: list, diner_name: str) -> list:

""" Return list of Restaurants in input list whose name matches input string. """

result = [ ] for r in diner_list:

if r.name == diner_name: result.append(r) return result def collection_add(diner_list: list, diner: Restaurant) -> list: """

Return list of Restaurants with input Restaurant added at end.

""" diner_list.append(diner) return diner_list def collection_remove_by_name(diners: list, diner_name: str) -> list:

""" Given name, remove all Restaurants with that name from collection. """

result = [ ]

for r in diners: if r.name != diner_name: result.append(r) return result restaurants()

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

When does payroll become part of inventory as a product cost?

Answered: 1 week ago

Question

5. Do you have any foreign language proficiency?

Answered: 1 week ago