Question: Write a function shop () that takes the following arguments, in this order 1. tilename: a file that you will need to input. The file
Write a function shop () that takes the following arguments, in this order 1. tilename: 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, 148, is a string, so you will need to convert 148 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 nuch 1 you want, name of product 2,how nuch 2 you want, etc... For example: Pringles,3,Butter,1' means you are buying 3 units of Pringles and 1 unit of Buiter. Hint: build a dictionary based on the file and look up prices by product names Note: If the shopping list string is empty, return oo. If there is an isemn in the shopping list that does not exist in the file, skip the item and continue processing the rest of the shopping list. Examples Content of 'pricesl.txt (irst line is not empty and all content is text) Chicken Quarters,1.49 Chicken Whole,1.19 Beef Ground, 2.99 Apples, .99 Bananas,.39 Raspberries, 1.99 Content of 'prices2.txt' (tirst 1ine is not empty and all content is text) vocados, 1.25 Carrots,1.00 Corn, 25 Pears,1.00 BroccolL, .99 Ketchup, 2.49 Mustard, 1.79 Vinegar,1.88 Content of 'prices3.txt (tirst 1line is not empty and all content is text) Honey..38 Maple Syrup,.56 Free Rice,0.0 Tuna,1.49 Garlic, 2.99 Ginger, 3.99 4st1- ist2 'Ketchup, 4,Mustard, 10,tooth paste, 1,Avocados, 1 1ist3 Tuna,1,Honey,1,Free Rice, 79,Ginger Bread, 4 Function Call Return Value shop ('prices!.txt,listl)0.0 shop (prices2.txt',ist2) 29.11 shop ('prices3.ext'list3)1.8
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
