Why is it that my cod results in 0 instead of adding the prices?


#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
}

Write your code below!

def compute_bill(food):
total = 0
for key in food:
if stock[key] > 0:
total = total + prices[key]
stock[key] = stock[key] - 1
return total


#2

indentation is very important in python !!


#3

def compute_bill(food):
total = 0
for key in food:
total += prices[key]
return total


#4

his / her code look correct , but i think the problem exist in indentation of the code ; but yours :confused: why you remove substracting from the stock , and also verify if the stock has the items !!