Stock doesn't look quite right!


#1



A Day at the Supermarket - 12. Stocking Out


I am getting following error-
stock doesn't look quite right! Make sure to not call compute_bill since it changes the stock! It should contain: {'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}


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

prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}


#2

I don't see your stock dictionary. If that is not in your program then you will need to add it. In compute_bill(), you are checking the stock in your if statement and there should not be an else. Your method should look something like below:

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


#3

I have the same code, running it I got the message:

Oops, try again. stock doesn't look quite right! Make sure to not call compute_bill since it changes the stock! It should contain: {'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}

I checked the stock adding lines
print item
print stock[item]

Above error message seems to be in contradiction with the instruction.
Can anyone help?


#4

I had the same error message but then I've deleted the code line that calls the function
(in other words- if after the function defenition you wrote the command "print compute_bill(shopping_list)"- so delete this line and run the code.)


#5

2 posts were split to a new topic: Getting an error


#6

good´╝îthank you very much!


#7

Thank you, very much!


#8

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