The objective of this project is to create a solution combining multiple concepts that have been presented in class, building off of the previous concepts of loops, string manipulation, and lists, along with the addition of:
dictionaries
user defined functions
files
As with project 2, note that you should only use techniques we have covered in class. Using more advanced concepts does not help your understanding of the basics, and is a red flag that the code may not be your own work. In particular, you may NOT use the Python break, quit, exit, continue or any other programming convention to prematurely exit out of a loop or your program. A thorough understanding of loops requires that you are able to structure the loop control correctly without using break or other forced exit. Even though you may pass the test cases, use of any of these instructions will result in a 20% reduction in your overall score. Do not use list or dictionary comprehension as a loop shortcut. If you know what this is and perfectly understand it, it is trivial for you to accomplish the same thing without list or dictionary comprehension. If you don’t know what it is, you should not be using it. If you have questions about this as you work on your program, discuss it with your class assistants or with the course instructors.
Description
Fictional restaurant Sparty Burger turned out to be a commercial success and they have since franchised across the country in the form of full-sized dine in restaurants, express restaurants, and food trucks. They need you to create a program that can analyze the revenue generated by their various restaurants. You will be given a CSV file that lists the store ids, locations (by state), store styles, and the revenues generated in the previous month. Your program will read through this file in order to perform its analyses. The analyses performed will be to count the number of restaurants in a given state, count the number of restaurants of a given restaurants, calculate the average revenue generated by restaurants in a given state, calculate the average revenue earned by restaurants of a given restaurants, and print the store that had the lowest revenue. For example, the program user may want to determine the average revenue of all restaurants in Alaska and then determine the average revenue of all restaurants in Michigan. To accomplish this, we will have a menu of options the user can choose from, as described below.
The first thing your main program will need to do is prompt the user for a CSV file name so that you can read the data pertaining to the restaurants. Your prompt must be exactly Enter the filename of the file containing restaurants data: (with a newline following the colon). You then need to read the file into the program so that the data can be used for the analyses. You do not have to worry about a user inputting an incorrect file name for the purposes of this project. In the real world, you might expect that there are not Sparty Burger restaurants of each style in every state. However, for simplicity in this project, you may assume that there is at least one restaurant of each style in every state.
Provided Input Files
An input CSV file with 1000 rows of data about restaurants is provided for you to use, and where most of the visible test cases will come from. The example file is named “Restaurants.csv”. The following are the first ten lines of this file:
id,state,style,revenue
985440,NV,dine in,247915.40
503958,KY,dine in,172806.17
894772,SD,dine in,209374.65
541001,HI,dine in,189545.15
142450,ID,dine in,243740.94
371493,MS,dine in,252821.10
636110,WA,dine in,156765.93
609532,AK,dine in,383282.52
524604,OK,express,322564.13
The first row is a header row and has the headings for what the items in each column represent. You can (and should) download this file and look at it with notepad or excel to see what the data looks like.
There is another file provided called TestFileRestaurants.csv which contains data of the same format, but only has 15 restaurants from 3 states. This is the file you should use initially so you can manually compute what the answers should be without relying on what the test cases are telling you should be your output. This is a much more realistic reflection of programming in real life. You need to try your program on some sample data to make sure it is computing things correctly – usually there will be no one to tell you if it’s right or wrong unless you verify it yourself.
In order to encourage you to do this kind of testing, the majority of the test cases will not be released right away. You should focus on getting your menus and loop structure correct, similar to what you did in project 2, and then use the test file to see if you are computing the correct values. The additional test cases will be released after 1 week.
There is a third file that your program will also be tested with that you can not download. This is to ensure that your program will work no matter what the filename, and no matter what the data is inside that file. This third file will follow the same format as the other two.
Menu
You will need to print out a menu where the user inputs which option they want. You may want to put this in a function, but it is not required that you do so.
The menu should be exactly as follows (the menu always prints a blank line first, and there is a newline after the Enter selection 1-6: prompt):
(1) Get the number of restaurants by state
(2) Get the number of restaurants by style
(3) Get the average revenue of restaurants by state
(4) Get the average revenue of restaurants by restaurant style
(5) Print restaurant with lowest revenue
(6) Exit
Enter a selection 1-6:
If the user enters an invalid menu selection (including a non-numeric input, or a number outside of the valid range), your program should not crash, but the function should print the message Invalid selection – must be a number from 1 to 6, display the menu again, and prompt the user for a valid selection. Hint: Think back to how you handled continuous prompting for project 2.
In the main program,
If the user selects options 1 or 3, the program will then prompt the user for a state and expects the input to be a two-character state abbreviation. State abbreviations are two capital letters but your program should be able to recognize the state abbreviation regardless of the character’s case. For instance mi, MI, Mi, and mI should all equate to the state abbreviation for Michigan. The prompt should be exactly
Enter a 2 letter state abbreviation, or ‘US’ for all restaurants in the U.S.:
(with a newline following the colon). The program will call a function for each of these menu selections and use the selected state as an argument to the function. If the user enters an unexpected input for the state, you should output the message
x is not a valid state abbreviation
(where x is the invalid string exactly as entered) and continue prompting the user until they provide a valid state abbreviation. A list of valid state abbreviations will be provided for you to use to check if the user input is a proper state abbreviation. Once the function returns, you will print an appropriate message such as
There are 24 Sparty Burger Restaurants in MI
or
The average revenue in MI is $25000.00
If the user selects options 2 or 4, the program should similarly prompt the user for a restaurant style. The prompt should be exactly
Enter the restaurant style, or ‘any’ for all styles:
(with a newline following the colon). Valid styles are “dine in”, “express”, and “truck”. Note how all of the styles are in all lowercase. The program should be able to identify these styles regardless of the letter cases in the input string. For instance Truck, TRUCK, tRuck, and any other variation of letter case should still evaluate as being truck. If the user enters an unexpected input for the style, you should output the message
x is not a valid restaurant style
(where x is the invalid string exactly as they entered it) and continue prompting the user until they provide a valid restaurant style. Again, when the function returns you should print out an appropriate message such as
There are 55 Sparty Burger truck style Restaurants
or
The average revenue of truck style restaurants is $25000.00
Average revenue should be displayed as dollars and cents. The restaurant style should be displayed in lower case.
Finally, selection 5 does not require any additional input – it looks through the entire list of restaurants for the one with the lowest revenue, regardless of state or restaurant style.
In addition to the valid selections for state abbreviations and the selections for restaurant style, the string ‘US’ should be a valid selection for the state, and ‘any’ should be a valid selection for restaurant style as well. The ‘US’ selection for the state will allow the program to search through the restaurants of all states and the ‘any’ selection allows the program to search through the restaurants of all styles.
Creating your dictionary
As you read in all of the lines in the file, you will create a dictionary of the data that you can use throughout the program. We are interested in various restaurants and the information associated with each one, so we will want to use unique information pertaining to each restaurant as the keys to the dictionary. For values, there’s more than one piece of information associated with each restaurant. You need to make the values in the dictionary a list containing that information, on the order it was given in the file. If you do not create your dictionary properly you will not pass the unit tests. Remember that the csv file contains a header row, which should not be included in the dictionary. Also note that when reading a csv file, everything comes in as a string (just like all input in Python), so think about which data elements need to be something other than string.
Required Functions
You will need to define and implement the following functions:
def count_by_state(parameter1, parameter2) – This function requires two parameters; the first is the dictionary of restaurants info, and the second is a string representing the state that we are interested in. The function will return an int value which represents the number of restaurants in the specified state. For example, if my dictionary is named Restaurants, calling the function using the code count_by_state(Restaurants, ‘MI’) would return the number of restaurants in Michigan.
def count_by_style(parameter1, parameter2) – This function requires two parameters; the first is the dictionary of restaurants’ info, and the second is a string representing the style of restaurant we are interested in. The function will return an int value which represents the number of restaurants of the specified style. For example, if my dictionary is named Restaurants, calling the function using the code count_by_style(Restaurants, ‘truck’) would return the number of restaurants that are food trucks.
def avg_by_state(parameter1, parameter2) – This function requires two parameters; the first is the dictionary of restaurants’ info, and the second is a string representing the state that we are interested in. The function will return a float value which represents the average revenue generated by the restaurants in the specified state. For example, if my dictionary is named Restaurants, calling the function using the code avg_by_state(Restaurants, ‘CO’) would return the average revenue of the restaurants in Colorado.
def avg_by_style(parameter1, parameter2) – This function requires two parameters; the first is the dictionary of restaurants’ info, and the second is a string representing the style of restaurants we are interested in. The function will return a float value that represents the average revenue generated by the restaurants of the specified style. For example, if my dictionary is named Restaurants, calling the function using the code avg_by_type(Restaurants, ‘express’) would return the average revenue of the restaurants that are express style restaurants.
def print_lowest_revenue(parameter1) – this function requires as its parameter the dictionary of restaurants info. The function will print out the information of the restuarant with the lowest, showing the restaurant ID, the state, the style, and the revenue like the following example:
Lowest Revenue: Restaurant 317298 in TX, express style, had $2445.99
Additional suggestion: You may find it easier to create a function to display the user menu. This may also help you minimize the number of lines of code you must copy to generate the menu wherever you need it in your program.
NOTE Checkpoint 1 requires passing tests that read the file, print your menu and accept input. However, you should also focus on building your dictionary during this week prior to checkpoint 1’s due date. Checkpoint 2 requires passing tests that require your function definitions be present. You do not need to implement the functions, and they do not need to work correctly in order to pass these test cases. So you should create function stubs for your functions (see zyBooks section 11.6) and fill in the details later. Warning! Even though you could pass the checkpoints with only function stubs, we strongly recommend you attempt to implement the details of at least one function before the checkpoint is due so you don’t run out of time in the following weeks.
Remember that your program needs to work with any file that follows the same format, even if it contains different data, and some of the hidden test cases will use an alternate file that you will not be able to see. Also, remember that the starter code contains several lists of data that will mimic the lists that will result when you ultimately read in your data file. You can use these to start the code that will build your dictionary and implement your functions. They will work the same regardless of where the data originally came from.

For This or a Similar Paper Click Here To Order Now