12/13 A Day at the Supermarket


#1

Hello ! HELP, I'm stuck !!

code is:

shopping_list = ["banana", "orange", "apple", "pear"]

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 i in food:
                 if stock[i] > 0:
                      total += prices[i]
        
          return total

compute_bill(prices)


#2

move total under def function and put : after it

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

#3

Thanks for you help, but the code isn't right. I got an error
Oops, try again.
calling compute_bill with a list containing 1 apple, 1 pear and 8 bananas resulted in 35 instead of the correct 27


#4

No need for the
'compute_bill(prices)'

or just move it into the def function by indenting it with 4 spaces


#5

I made it, thanks!
That's the right code.
def compute_bill(food):
total = 0
for i in food:
if stock[i] > 0:
total += prices[i]
stock[i] -= 1

return total

I have also indented the code. I have copy/pase the code and there no added indenting in copying. :confused: