Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 Code I keep getting the wrong expected values when I put it through testing. def shop(filename, shopping_list): price_list={} total_price = 0 try :

image text in transcribedimage text in transcribedimage text in transcribedPython 3 Code

I keep getting the wrong expected values when I put it through testing.

def shop(filename, shopping_list): price_list={} total_price = 0 try: with open(filename) as f: content = f.readlines() for line in content: single_item = line.split(',') price_list[single_item[0]]=float(single_item[1]) shopping_list = shopping_list.split(',') for i in range(0,len(shopping_list)): if(i%2 == 0): item_price = total_price+float(shopping_list[i])*item_price return total_price except IOError: print("Error: Unable to open", filename) 
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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

Develop knowledge of the Italian entrepreneurial business context.

Answered: 1 week ago