Please help with Stocking Out


#1



Please help me with this, I am so confused. What I am doing wrong? Thanks in advance.

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


This is what I get:
Oops, try again. calling compute_bill with a list containing 7 bananas resulted in 28 instead of the correct 24


Replace this line with your code.


#2

can you post your full code?


#3

Thank You for the fast answer. This is the full 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 item in food:
        if stock[item] > 0:
            total += prices[item]
            stock[item] -= 1
    return total

#4

that is weird, if you call the function (which you shouldn't):

print compute_bill(['banana']*7)

the output is 24, the only reason this error message would occur is because the stock isn't properly reduced, try refreshing the page


#5

Yes it is so weird, I refreshed the page and worked. Thank you so much for the help..

Kindly regards.


#6

it seems you where sending cached data to the server for validation, good it is solved now :slight_smile:


#7