Why the output is 0?


#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:
total = total + prices[item]
stock[item] = stock[item] - 1
return total
print total


#2

Anything after return is unreachable, so the print statement is never seen (assuming it is still inside the block). Without formatting, we cannot tell where the indentation is in your code so all we can do is speculate.

If you really want or need help, especially in the Python track, we need three things,

1. link to exercise
2, error messages
3. formatted code sample.

Search the forums for `How to format code samples when posting’.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.