# Stocking out

#1

``````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
for item in food:
if stock[item] > 0 :

what is wrong with this code
this the 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

#2

inside your if condition, you should add the cost of item to total, and reduce the stock of that particular item

Then after the for loop (indention is important here) you should return total

#3

stock[item] -= 1 like that the cost

#4

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

this my code and this new 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

you should only reduce stock if there is stock

You don't add anything to total, when you reduce stock you should also charge the client for what they are buying

The indention on your return is still not good, but i already explained that in the other topic you created (for a earlier question)

#6

i cant make good indention here because when i write it dont make indention

#7

but you can change indention's with the delete key, backspace, tabs and spaces?

The IDE is trying to help you, it doesn't always get it right, in which case you can change the indention's

#8

look sorry but can you explain it by code it keeps giving me errors

#9

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

total += stock[item]
stock[item] -= 1

i did it like that but still ...........

#10

the indention of your return is still not good. i do markup for your code, so i see the indent as it would be in the exercise, so you need to work on your indention in the exercise. Return needs to be at the same indent level as the for loop so the whole for loop can run.

#11

i did return in the same indention as the loop but this error appeared:
Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 30 instead of the correct 7

#12

thans finally i answered it my mistake was that i didnt add prices you know i have to add the item to the price then decrease it by one in stock