Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Please help me to understand the concept behind it

I am trying to build a function where it should return true or false based on the input. its function to check the year we will pass a input to check its a leap year or not. I found this from google but I am not getting the concept behind it. Please help.

def is_leap(year):
    leap = False
    if year % 4 == 0:
        if year % 100 == 0:
            if year % 400 == 0:
                leap = True
            else:
                leap = False
        else:
            leap = True
    else:
        leap = False
    return leap

1 Answer

Philip Schultz
Philip Schultz
11,437 Points

Hey Afrid, Have you seen this article- This somewhat explains what is going on. Take a look at all of the answered question at the end of the article if there is something more specific. https://www.wikihow.com/Calculate-Leap-Years

Thanks Philip, it helps.