Making purchase Error please help


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;

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


Got it Return has indentation error and i solve it


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.


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


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:


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