12. Stocking Out


i keep getting this message but i cant figure out why.
i checked all posts about it this exercise but i just dont get it
Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 2 instead of the correct 7

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 food:
        if stock > 0:
            total += prices[item]
            stock[item] = stock[item] - 1
        return total


a function ends the moment a return keyword is reached, this currently happens inside the first run of your loop, change the indent of return so the whole loop can run


i also had to replace item with number and now it runs. Thank you!


this is all good but does it return the remaining stock or does it only bring the total (since return total is the last argument)


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