Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,343 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.