Stocking out


#1

I am getting this indentation error.
I did a backspace and brought the error line on the line above and then pressed enter but still I see the error.

File “python”, line 23
stock[item] = stock[item] - 1
^
IndentationError: unindent does not match any outer indentation level

Code:

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

print total

#2

somehow pasting the code here doesn’t not show any indentation.


#3
for item in food:
    if stock[item] > 0:
    	total += prices[item]
      stock[item] = stock[item] - 1

It could be a case of mixed tabs and spaces. Be sure the two lines inside the if statement have the same indentation characters (typically four spaces).


#4

I found the error. but not able to delete the comment


#5

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