I cannot understand and correct this error


#1

Here is the strange thing,I did make indentation for wherever the indentation error is,and when I copied my code here, the place I had made my indentation(also the place showed in error message) just does not have any indentation.WHAT is going on???

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

File “python”, line 22
total = total + prices[item]
^
IndentationError: expected an indented block


#2

The problem is that I did make a tab for “total = total +prices[item]” and " stock[item] -= 1" ,OK, I had made that ■■■■ indentation in the script and It just dose not work,I cannot believe I wasted 30 minutes in this stupid error.


#3

What tab means is to indent until the next multiple of 8 characters (and because it has such a complicated behaviour it’s better to use spaces)


#4

bro,I actually followed the initial automatic indentation, after : , I pressed enter and it was wrong, then I started to make indentation by tab and It was wrong again.Now it suddenly becomes alright. And yesterday I tested my codes in Chrome and it was fine also.Perhaps the only reasonable explanation is that ■■■■ hits the fan everyday in my life and i have to get used to it.Thank you anyway.


#5

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