# 12/13, Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 9 instead of the correct 7

#1

Here is my whole code,

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

shopping_list = ["banana", "orange", "apple"]
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
total=0
food = stock
def compute_bill(food):
total = 0
for x in food:
total += prices[x]
def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] -= 1

#2

I am new to coding as well and just got to this. It took me a little bit to figure out that my indents were off. So I would say just to make sure that your indents are in the right place, especially on the return.

Hope this helps.

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

stock = {
----"banana": 6, ------------------------ <-one tab
----"apple": 0, --------------------------- <-one tab
----"orange": 32, ----------------------- <-one tab
----"pear": 15 --------------------------- <-one tab
}

prices = {
----"banana": 4, --------------------- <-one tab
----"apple": 2, ------------------------ <-one tab
----"orange": 1.5, ------------------- <-one tab
----"pear": 3 -------------------------- <-one tab
}

def compute_bill(food):
----total = 0------------------------<-one tab
----for x in food:-------------------<-one tab
--------if stock[x] >=1: ----------- <-two tab
------------total += prices[x] ----- <-three tab
------------stock[x] -= 1 -----------<-three tab

#3

Hi coolyoshi7,

I had the same exact problem, and I spent really long trying to figure it out. Your first two blocks look good, and the other reply by lchapin89 has the correct indenting. It turns out, at least for me, that the catch was the += and and -=. Instead of using those operators, you have to write it out like:

total = total + prices[item]

It's a little confusing, since the instructions are a bit misleading. So here's my last block of code with the function:

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

``return total``

That's without the indenting, of course. That worked for me, and I hope it works for you. Hope this helps!

#4

Hasn't worked for me error Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 0 instead of the correct 7

#5

I think it is a bug form IDE, my code doesn't run right too.

shopping_list = ["banana", "orange", 'banana', "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 i in food:
if stock[i] > 0:
total = total + prices[i]
stock[i] = stock[i] - 1

``return total``

print compute_bill(shopping_list)

#6

A , I find the solution.

Delete the line "print compute_bill(shopping_list)"