I need an explanation for this Python question to help me study.
Background Information
- Some stores are expensive; others are less so. Our mission is to generalize a grocery store into one of three categories: typical, cheap, or expensive. We’ll do this by going through each line of a receipt, and calculating the average cost of a single item including tax.
- Let’s say a “typical” store has an average cost of $3 to $5 for an item. If it’s less than that, we’ll call it “cheap,” and a higher average cost will get our “expensive” rating.
- Example Receipt: There are two entries. The first line shows 3 of some item (at $4.25 ea) for $12.75, and second is one item for $6.90. Sales tax is 2.5 percent.
- Example Receipt Cruncher Calculation: 12.75 + 6.95 + $0.4925 tax is $20.1925. We have 4 items, and 20.1925 ÷ 4 is 5.048125, so we’d end up labeling that store as “expensive” (just barely!)
Assignment
- Write a Python program that prompts the user for the number of entries on a receipt, and then for each entry prompts the user for the number of items in that entry, followed by a prompt for the cost of the entry. Output the unit price of each item.
- After all of the entries have been entered, prompt the user to enter the sales tax (ex: 5.3)
- Calculate the average price per item, and output whether store should be considered typical, expensive, or cheap. If it’s answer is expensive or cheap, consider the sales tax, and explain that may have impacted the rank. (See below for details.)
- See the sample transcript below. You can assume that all user inputs will be valid when we test the program. Your solution should match the output format exactly.
Grading – 100 points
- 35 points – The Average Cost Per Item calculation is correct.
- 15 points – The user is prompted to enter the number of entries from the receipt (5 points), the price of each entry (5 points) and the quantity of items on each entry (5 points).
- 10 points – With the exception of the actual average cost per item, the output format matches the output format of the transcript exactly (2 points for each type of difference up to 10 points).
- 5 points – The average cost per item is displayed with two digits to the right of the decimal. (Look up how to round numbers in the Python documentation.)
- 10 points – A function named get_rating is defined that takes four float parameters (item, lo, hi, tax) and correctly returns a rating as a string (e.g. “cheap”, “expensive”, or “typical”… or one of the outputs below…)
- NEW! in the case of an extra high tax (5% or more) or an extra low tax (less than 2%) output the following:
- (extra high tax): expensive, but you could blame that on the X% tax. (where X is the amount of the tax)
- (extra low tax): “cheap, but it helps that the sales tax is X%!” (where X is the amount of the tax)
- NEW! in the case of an extra high tax (5% or more) or an extra low tax (less than 2%) output the following:
- 10 points – A function named main is defined (5 points). The only python statement that does not appear in this function or the translate function is the call to the main function, e.g. main() (5 points).
- 10 points – The Python solution is easy to understand and does not contain unnecessary code (2 points for each type of improvement up to 10 points).
- 5 points – An appropriate Python comment appears at the top of the submission. See below for the type of information that should appear.
Sample Python Header Comment
# ---------------------------------------_x000D_ # CSCI 127, Joy and Beauty of Data_x000D_ # Program 1: Receipt Cruncher_x000D_ # Your Name(, Your Partner's Name)_x000D_ # Last Modified: January ??, 2020 _x000D_ # ---------------------------------------_x000D_ # A brief overview of the program._x000D_ # ---------------------------------------_x000D_
Sample Transcripts
How many entries are listed on the receipt? 1
Enter number of items in entry 1: 2
Enter that entry’s total cost: 8
Cost per item of entry 1 is: 4.0
Enter sales tax (%): 4
total cost (with tax): 8.32
total number of items: 2
average cost per item is 4.16
That store seems typical
How many entries are listed on the receipt? 1
Enter number of items in entry 1: 2
Enter that entry’s total cost: 9.98
Cost per item of entry 1 is: 4.99
Enter sales tax (%): 7.5
total cost (with tax): 10.73
total number of items: 2
average cost per item is 5.36
That store seems expensive, but you could blame that on the 7.5% tax.