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>

<blockquote>
  <p>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</p>
</blockquote>

<p>No that isn't completely true. That <code>else</code> block is only executed when the first <code>if</code> block is not i.e when the year is not divisible by 4. When the other <code>if</code> blocks are not (e.g for a year divisible by 4 and not by 100), the function will rightly <em>return</em> <code>None</code>.</p>

<p>Instead, you can <code>return False</code> in the case everything other <code>if</code> fails:</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
        return False
</code></pre>

<p>That said, I'm not sure about the correctness of your approach. Here is an SO post that can help you improve your code:</p>

<p><a href="http://stackoverflow.com/questions/11621740/how-to-determine-whether-a-year-is-a-leap-year-in-python">How to determine whether a year is a leap year in Python?</a></p>

<hr>

<p>Otherwise, you may find out if a year is leap using <a href="https://docs.python.org/2/library/calendar.html#calendar.isleap" rel="nofollow"><code>calendar.isleap</code></a>:</p>

<pre><code>import calendar

print(calendar.isleap(2000))
</code></pre>

python