Whey is_leap_year returning None instead of True
<p>Why does this code print None instead of True. It seems that once it checks if it divisible by 4 it does not go on to check the other requirements. From my current understanding, for each successive if statement it should keep going down and checking the next if until one of them is false. At which point it should go the the else statement and return False. But, obviously I'm doing something wrong. Thank you.</p>

<pre><code>def is_leap_year(year):
        # step 1 check if dvisible by 4
        if year % 4 == 0:
            print "year is divisble by 4"
            # step 2 check if divisible by 100
            if year % 100 == 0:
                print "year is divisible by 100"
                # step 3 check if divisble by 400
                if year % 400 == 0:
                    print "year is divisible by 400"
                    return True
        else:
            return False

print is_leap_year(1996)
</code></pre>

<p>The <code>else</code> refers only to the first <code>if</code> - i.e. for years not divisible by four. Therefore for a year divisible by four, but not by 100 you do not fall into the <code>else</code>. Python functions return <code>None</code> if no return value is specified.</p>

<p>In general <code>else</code> refers to the last <code>if</code> with the same indentation.</p>

<p>You can fix it by doing:</p>

<pre><code>def is_leap_year(year):
# step 1 check if dvisible by 4
if year % 4 == 0:
    print "year is divisble by 4"
    # step 2 check if divisible by 100
    if year % 100 == 0:
        print "year is divisible by 100"
        # step 3 check if divisble by 400
        if year % 400 == 0:
            print "year is divisible by 400"
            return True
    else:
        return True
return False
</code></pre>

python