12/13 Stocking out


#1

I read the comments on other entries for the stocking out lesson. However I have the return value directly under the for loop but I am still getting this error: “calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 9 instead of the correct 7”. I am unsure what is wrong,
Here is my code

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


#2

I figured it out. I was missing [f] in the if statement behind stock.


#3

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