I get the correct answer, but getting an error msg


#1

Here is my code ( i have added several prints for debugging):smile:

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:
#note here that I go to prices (outside of the function)
print "item:",item, " price:", prices[item], "stock:", stock[item]
if stock[item]>0:
total += prices[item]
stock[item]=stock[item]-1
#put in inventory reduction here
return total
print shopping_list
print stock
n=compute_bill(shopping_list)
print "Total:", n
print stock

and here is the results I get:

['banana', 'orange', 'apple']
{'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}
item: banana price: 4 stock: 6
item: orange price: 1.5 stock: 32
item: apple price: 2 stock: 0
Total: 5.5
{'orange': 31, 'pear': 15, 'banana': 5, 'apple': 0}
None

Which to me looks perfect. BUT I get the following error:

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}

Please tell me how to create the proper indentation in my preview (is it because I am using TAB and not four spaces?) Can anyone help?


#2

Answered in this post