Making a purchase 11 PLEASE HELP


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


it says compute_bill(['apple']) returned 7.5 instead of 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


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


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.


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.


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!

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


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...


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
    return total


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!!!


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


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



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


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

Write your code below!

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

print compute_bill(shopping_list)




  1. A “topic” is a forum thread. For example, this is a topic
  2. A “post” is a post on a topic. For example, this is a post
  3. The “Composer” is the place that you type and preview a post in, at the bottom of your screen