Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(f) Now, let's try to incorporate menus into the full Restaurants program. Start by downloading a clean copy of the first version of the restaurants

(f) Now, let's try to incorporate menus into the full Restaurants program. Start by downloading a clean copy of the first version of the restaurants program; if you're confident in the version you modified in part (d), you may start with that version instead. For this part, create a separate file called restaurantsf.py. You'll turn that file in along with your lab5.py file and the restaurantsd.py file you created earlier. Our advice about taking things slowly and methodically applies here as never before. If you find yourself running out of time at the end of the week, it may well be because you weren't methodical enough about making changes to this code. 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. Finally, if you have time, also incorporate a top-level command that selects restaurants with prices at or below a specified value, reusing the code you defined above where appropriate.

(g) Write a function called letter_count that has two strings as parameters. The function examines its first parameter, counting certain letters; the second parameter is a string that specifies which letters to count. Thus, letter_count(some_message, 'aeiou') would return counts of the vowels in the string some_message and letter_count(some_message, ' \t ') would return counts of the white-space characters (space, tab, and newline). The function should return its counts as a list of Count namedtuples, where a Count namedtuple has two fields, letter and number. [Okay; go back and read that again, two or three times, until it's clear. It's important to be able to read specifications that use technical terminology. The following example may also help.] Calling letter_count('The cabbage has baggage', 'abcd') should return [Count(letter='a',number=5), Count(letter='b',number=3), Count(letter='c',number=1), Count(letter='d',number=0)]. So how do you go about this? You need to break it down into parts. First, follow the design recipe: Write a function header with the types of the parameters and the type of the return value; write a docstring "purpose statement"; and write some examples of calls to this function and the expected results (in the form of assert statements). That may take a few minutes, but it's time well spent at this stage. Second, define the Count namedtuple. Third, and this is always a good idea when you're designing a function that does the same thing (count occurrences) with multiple values (the vowels or whatever), design and write a function that does the task with one value (i.e., takes a string and a single character and returns a single Count namedtuple with the character and the number of times it occurs in the string); the body of this function can be one line that calls a string method (see if you can find it in the book or in help(str)). Fourth, write the body of the main letter_count function, where the task is to call the count-one-character function for each of the characters you're counting, building up the list of Counts and returning it at the end. For purposes of this assignment, treat upper and lower case characters as distinct; that will make the coding easier. But you should consider how you could modify your function to count upper and lower case versions of the same letter together.

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_2

Step: 3

blur-text-image_3

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

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions

Question

=+21.18. Use (21.28) to find the generating function of (20.39).

Answered: 1 week ago

Question

How We Listen?

Answered: 1 week ago