Stocking Out exercise continually returns strange error


#1

I've tried a few things here and there to get my code to work, and I am continually getting this error message:

Here is my code as follows:

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(shopping_list):
    total = 0
    for x in shopping_list:
        if (stock[x] > 0):
                total = total + prices[x]
                stock[x] = stock - 1

What am I doing wrong? I feel like this should work. Any help is appreciated!


#2

stock is the dictionary. stock[x] is the value.

stock[x] -= 1

#3

Thanks! I made that change and it looks like that helped a little, although now it's producing this error message:

I'll take a look myself to find out what may be going on, but if there's any more insight anyone can offer, it'd be fantastic.


#4

Remember to return a total.


#5

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