#1

def compute_bill(food):
total=0
for food in shopping_list:
total += prices[food]

compute_bill(["apple"])

it says compute_bill(['apple']) returned 7.5 instead of 2

#2

your function is wrong as in food argument you should pass a list of your shopping items, so when you do a for loop on it it should be as:
`for item in food:`
so your `item` is an each element on your shopping list so with that item you fetch prices:
`total += prices[item]`
I think now it should work

#4

Oh thank you, I got it! It was just a problem with the return part, I put it 4 spaces more........

#6

I can't finish this one either! They say in the problem to subtract one unit for each item purchased but when we run the code, we get a message saying we changed the variable stock.

#7

why do you decrease your stock in line: `stock[item] -= 1` ?? I do not remember what they asked for exactly but I do not think it was decreasing the stock.

#8

They say in point 2:

If the item is in stock and after you add the price to the total, subtract one from the item's stock count.

So, I have decreased the stock for each item purchased!

Edited;
Maybe I'm in the wrong thread!
I'm trying to complete the "Stock out" problem!

#9

Something is really wrong in the site checking code...

This is not right... The argument sent to the compute_bill function doesn't have 9 bananas...

#10

sorry, my bet, indeed it asks for decreasing stock. I think the problem is that you put a space between variable and its index fe. `stock [item]`, they should be together. here's my code that worked:

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

#11

Ok, this is ridiculous....

We are not supposed to use the function just yet!!! I commented out the line where I use the function and everything went right!!!

Lol, they tell us to make a function and then we are not allowed to use it even for testing purposes??? This is non sense!!!

#12

that's the course, you learn by following the path but true sometimes instructions are misleading.

#13

I can not do it either!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Help!!!!!!

#14

@systempro52677

If you have a problem, please post this in a new topic with your question + error messages + code

#15

How come I am not getting the right total?

Here is my error:

Oops, try again. compute_bill(['apple']) returned 3 instead of 2

Here is my code

shopping_list = ["banana", "orange", "apple", "pear"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

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

def compute_bill(food):
total = 0
for food in shopping_list:
total =+ prices[food]