Stocking Out


#1

Hello,

I'm getting this error for Stocking Out:

Oops, try again.
calling compute_bill with a list containing 1 apple, 1 pear and 1
banana caused the following error: unsupported operand type(s) for -:
'dict' and 'int'

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

I also tried:

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

But it gives me the same error.

Thanks in advance.


#2

Left side is a dict, right side is an int
What does subtracting 1 from a dict do? Python doesn't seem to have defined a behaviour for that, and tells you so.


#4

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