# 12. Stocking out

#1

Can anybody explain me what am i doing wrong with this code?

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

this code return me errror:
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}

#2

In line 6, you should have:

stock[item] = stock[item] -1

Or at least it worked for me!

#3

i’ve changed as you said, but its still the same…

#4

Oh, sorry to hear that!
My code looks like this:

#5

It’s strange. the code is working, but it won’t to accept.
So, i will miss this lesson, and keep going

#6

thats my code and it’s working

#7

Remove line 26.

I have the same code as you, but I removed 26 and it worked for some reason

#8

Hey! It’s worked! Thank you very much! You are great!

#9

not working

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 n in food:
if stock[n]>0:
total+=prices[n]
stock[n]=stock[n]-1
Oops, try again. compute_bill([‘apple’]) returned 0 instead of 2

#10

This is the same error I’m receiving. My code is identical to the examples above. What gives?

#11

Well, I was able to get the module to accept my code, but I really don’t think it was right. It calculated the cost of buying every single banana, orange, and pear in the list. When I call “compute_bill(shopping_list),” it returns the right amount, but gives me an error message and won’t move on.

#12

Does it have to do with white space?
total=0 is not the same as total = 0, etc…

#13

Well, actually, I just tried it both ways and it worked. Please disregard

#14

I did the same thing as you guys.
Just remove any thing extra like the print thingy.
Here’s my code:
http://pastebin.com/mEYJ6C7d