Question: Python 3 Write a function shop ) that takes the following arguments, in this order: 1. filename: a file that you will need to input.

Python 3

Python 3 Write a function shop ) that takes the following arguments,

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 t: Pringles,1.48 Note: content like , Pringles, 1 48, 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 much 1 you want, name of product 2, how much 2 you wat, 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. Note: If the shopping list string is empty, return 0.0. If there is an item 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 'prices1.txt' (first 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' (first line is not empty and all content is text) Avocados,1.25 Carrots,1.00 Corn, .25 Pears, 1.00 Broccoli, .99 Ketchup, 2.49 Mustard,1.79 Vinegar,1.88 Content of 'prices3.txt (first line 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 ist1 - list2Ketchup, 4, Mustard, 10, tooth paste, 1,Avocados, 1 list3-Tuna, 1, Honey, 1,Free Rice, 79, Ginger Bread, 4' Function Call shop (' prices1.txt, list1)0.0 shop ('prices2.txt',list2) 29.11 shop ('prices3.txt Return Value ist 3)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!