11.Making a Purchase


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

Can you guys explain me what is wrong with my code ?Also can you explain me how does (food) argument refer to the keys in the dictionary above the function ?

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):
for loop in food:
return total


Hey yes the return statement must be outside of the loop.
I think you have the statement inside the loop and therefore it stores only the one number in the Return and overwrites each time.

liebe grüße



def compute_bill(food):
----total = 0
----for loop in food:
--------total += prices[loop]
----return total


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