I'm missing something!


#1

After a number if tries and a long walk, I not seeing what is wrong. A little help please.

shopping_list = ["banana", "orange", "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(shopping_list):
total = 0

for item in shopping_list:
    total += prices[item]
print 'total: ' +  str(total)

compute_bill(shopping_list)

LEFT PANEL: total: 7.5 none:

"Oops, try again. calling compute_bill with a list
containing 1 apple, 1 pear and 1 banana resulted in
None instead of the correct 7 "

Changed the 'for' statement to:

for item in shopping_list:
if stock[item] > 0:
total += prices[item]
stock[item] -= 1
return total

Factoring in the 'stock' helped.


#2

and your shopping-list
shopping_list = ["banana", "orange", "apple"]

You could call the compute-bill function,
using an argument ["apple","pear","banana"]
like

compute_bill( ["apple","pear","banana"] )

#3

Thanks for the input.