12. Stocking out


#1




This is the error message
Oop, try again. stock doesn't look quite right. Make sure to not call compute_bill since it changes the stock! It should contain: {"orange":32,"pear":15,"banana":6, "apple":0}


It prints 5.5 as total and also if I try to print stock looks correctly ¿What is happening?


And my code
# Write your code below!
def compute_bill(food):
    total = 0
    for item in food:
        if stock[item] > 0:
            total += prices[item]
            stock[item] -= 1
    return total
    
print (compute_bill(shopping_list))


#2

your function call:

print (compute_bill(shopping_list))

will change the stock before the validation can run, remove the function call. (the error message tells you so)


#3

Thanks, now it works.

In case you want to print the total what should you do?


#4

add a function call. This would work fine outside the exercise, but it causes problems for the lesson validation


#5

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