Stocking Out


#1



Stocking Out


File "python", line 23
SyntaxError: can't assign to function call
Oops, try again. Your code looks a bit off. See the console window for the error. Check the Hint if you need help!


I not sure what's wrong. I read some problems of others and i still dont get it. Help! Thanks in advance.


Replace this line with your 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(food) > 0:
            total += prices[food]
            stock(food) -=  1
    return total


#2

I'm assuming you mean brackets instead of parentheses for here:

And:

as you are suppose to use brackets to access index, also you use "item" in your for loop, but not in the code under the for loop. Make sure to keep your variables consistent. If you fix all that your code should be like this:

def compute_bill(food):
    total = 0
    for item in food:
         if stock[item] > 0:
            total += prices[item]
            stock[item] -=  1
    return total

Hope that helps! Message me if you need help after that. :slight_smile:


#3

Oops, try again. compute_bill(['apple']) returned 0 instead of 2. its showing this error


#4

I would need your code as well to help you, can you please post it. :slight_smile:


#5

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