Python allows mixing tabs and spaces. Before interpreting the source, python interpreter replaces tabs with spaces in such way that each tab is aligned to 8 spaces (see the doc on indentation).
If your editor is set to show tabs as 8 spaces, that should actually work as expected, but if it shows tabs as 4 spaces, then what it looks like is nothing like what the interpreter sees.
The code from the question is:
import calendar
def leapyr(year1, year2):
4 spacescount = 0
4 spaceswhile year1 <= year2:
tab4 spacesif calendar.isleap(year1) == True:
tabtab4 spacescount = count + 1
tabtabyear1 = year1 + 1
tabprint count
tab
leapyr(2008, 1015)
That is interpreted by Python as:
import calendar
def leapyr(year1, year2):
count = 0
while year1 <= year2:
if calendar.isleap(year1) == True:
count = count + 1
year1 = year1 + 1
print count
leapyr(2008, 1015)
This has an indentation error in line 8, at year1 = year1 + 1
.
The solution is to configure the editor to always use spaces, i.e. to replace tabs with 4 spaces.