It returns 10.5 for apple instead of 2


#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
}

# Write your code below!
def compute_bill(food):
    total = 0
    for item in prices:
        total += prices[item]
    return total

#2

here:

for item in prices:

why do you loop over prices?


#3

then on what we should loop over?


#4

lets add some function calls:

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

print compute_bill(shopping_list)
print compute_bill(['apple'])

Each function call represent a customer and the product they want to buy.

Back to the function calls, we supply an argument (shopping_list for example) when we call the function

the argument gets copied into the function parameter

so, what should you loop over?


#5

we shud loop over food it works checked


#6