# Stocking Out

#1

Hi Guys,

I am getting this error - calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 0 instead of the correct 7.

# Code:

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:
while stock[key] > 0:
total = prices[item] + total
stock[key] - 1

#2
``````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 displayStock():
total = 0
print "Product\tStock\tPrice\tValue"
print "=======\t=====\t=====\t====="
for item in stock:
stValue = stock[item] * prices[item]
print item+"\t"+str(stock[item]) +\
"\t"+str(prices[item])+\
"\t"+str(stValue)
total += stValue
print "\t\t\t-----+"
print "= Total stock-Value: \t"+str(total)+" =\n"``````

#==

``````def compute_bill(food):
displayStock()
#
total = 0
bought  = []
toOrder = []
print "Shopping-list: "+str(food)
for item in food:
if stock[item] >= 1:
stock[item] -=1
total += prices[item]
bought.append(item)
else:
print item + " stock: " + str(stock[item]) +\
" price: "+ str(prices[item])+" == stock < 1 =="
toOrder.append(item)
print "Bought:\t\t"+str(bought)
print "To order:\t"+str(toOrder)
print "Shopping payable \$"+str(total)+"\n\n"
displayStock()
# total = prices[item] + total
#     stock[key] - 1
``````theBill = compute_bill(shopping_list)