CodeAcademy code verification issue? 12/13


#1

I am not that experienced in python but I was wondering if this code is in fact correct? Compared to codeAcademys soluton?

My Solution:

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

CodeAcademy:

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

#2

this:

stock[item] - 1

is not reducing the item in stock, i always demonstrate this with the following example:

x = 5
print x # 5
print x - 1 # 4
print x # 5
x = x - 1
print x # 4

you just temporary subtract one, you don’t update the variable


#3

Thank you very much. I understand now.


#4