Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python 3 if __name__ == \'__main__\' : Part III: Grocery Shopping (20 points) Wr

ID: 3603321 • Letter: P

Question

Python 3

if __name__ == '__main__':

Part III: Grocery Shopping (20 points) Write a function shop ( that takes the following arguments, in this order: 1. filename: a file that you will need to input. The file contains many lines of grocery items and their cor- responding prices. In each line, the format is: name of product,price per unit. For example, a line of the file might look like this: 'Pringles,1.48 Note: content like Pringles,1.48' is a string, so you will need to convert 1.48 to a floating-point number when calculating the total price. For example, float ('1.48 would return the floating-point 1.48. In practice your code will pass a variable to float as an argument (not a literal string as shown here). Also, the quotation marks in the above example do not actually exist in the file - they are shown just to remind you that the file contains strings. 2. shopping.list: a string that represents a list of things that you want to buy during this shopping trip. The format is: name of product 1,how much 1 you want, name of product 2, how much CSE 101 - Fall 2017 Lab #7 Page 4 2 you want, etc.... For example: 'Pringles, 3,Butter,1' means you are buying 3 units of Pringles and 1 unit of Butter. Hint: build a dictionary based on the file and look up prices by product names.

Explanation / Answer

if __name__ == '__main__':