Total equals 9 not 7


#1

When i run this code

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

It tells me 1 apple 1 pear and 1 banana equals 9 not seven but based on the price dictionarie 9 would be the correct answer


#2

a function ends the moment a return keyword is reached, so the function ends when return total is reached, so the line of code which is suppose to reduce the stock, is never reached


#3

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