Stocking out not returning the right stock value


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/2/3?curriculum_id=4f89dab3d788890003000096#


I get this 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}"


I am confused as to why I get this error, can someone please explain?


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


Thank you


#2

You're calling the function here:

Remove it and you won't get that error message.


#3

your issue is here

     if stock[item]>0:
         total += prices[item] 
         stock[item]= stock[item]-1

it needs to look like this

     if stock[item]>0:
         total = total + prices[item] 
         stock[item]= stock[item]-1

Then you can run the function and output the bill.


#4

thanks for this, that last line was what i needed to fix my code


#5

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