Making purchase Error please help


#1

shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
def compute_bill(food):
total = 0;
for item in food:
total = prices[item]+total
return total;

ERROR IS
Oops, try again. compute_bill(['banana', 'apple', 'orange', 'pear']) returned 4 instead of 10.5


#2

Got it Return has indentation error and i solve it


#3

Hi Ramdas, I also think the whole function has an indention error i.e the function after defined all lie on the same line as the def compute_bill(food).

You could look into that.


#4

But the total should return out of that function so now my above code is worked


#5

Yes it should. It would print 'None' because thats the default print of a function that has been run through.

Yes your above code is worked :slight_smile:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.