Getting an error


I am getting a similar error:

Oops, try again. calling compute_bill with a list containing 2 apples, 3 oranges and 7 bananas resulted in 32.5 instead of the correct 28.5

I have run the same code multiple times and received different totals each time:

Oops, try again. calling compute_bill with a list containing 2 apples, 1 pear and 7 bananas resulted in 31 instead of the correct 27

Write your code below!

def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] - 1
return total
n = ["banana", "apple", "orange", "pear"]
print compute_bill(shopping_list) #I have also run this with (n) instead of (shopping_list)

Stock doesn't look quite right!

This needs to be reassigned.

stock[item] -= 1



Now I'm getting the same error as the OP:

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}

Code in the compiler says: "8.5" none"


That is the kicker. Comment out the call, or remove it for this lesson.


Thank you for your help.

I'm really not sure why this worked though?


The SCT runs the code and expects a certain output. If we run it first, then stock is not the expected amount.


So basically it ran through the lines including the print compute_bill which stopped it from looping back through the other items?


It would have looped through everything, but if the stock quantities are changed before that, the values expected won't show up in the results.


Thanks for all of your help. I 'think' I get it now!


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