Stocking Out Issues


#1



12. Stocking Out


I put in this code exactly, which has proven to work for other people, but it still doesn't work for me. I keep getting the error message: "Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 16 instead of the correct 7" I still have no idea what's wrong...


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


#2

here..you're adding extra amount..
total = total + prices[item]

hint**
that line of code adds items price without checking stock , so you need to remove it as at every loop ,you're adding price two times (inside for loop and then inside if statement)


#3

That worked! Thanks so much :grin:


#4

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