1000 Python Questions
Get 1 Python question daily. Join this telegram channel https://t.me/python1000questions
Advertise with us
program   0   8648
Python program to find whether a given year is leap year or not

We add a Leap Day on February 29, almost every four years. The leap day is an extra, or intercalary day and we add it to the shortest month of the year, February.

In the Gregorian calendar three criteria must be taken into account to identify leap years:

(1) The year can be evenly divided by 4, is a leap year, unless:

        (2) The year can be evenly divided by 100, it is NOT a leap year, unless:
                (3) The year is also evenly divisible by 400, Then it is a leap year.

This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.

Below is the python code to satisfy above three conditions hence finding whether an inputted year is leap year or not.

# Program to confirm is a given year is leap year or not
# year is provided at runtime.
# Author: https://www.pythoncircle.com

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

    return leap

if __name__ == '__main__':

Copy the above code in a file and save it with the name leap_year.py and run using the command python3 leap_year.py.

program   0   8648

0 thoughts on 'Python Program To Find Whether A Given Year Is Leap Year Or Not'
Leave a comment:

*All Fields are mandatory. **Email Id will not be published publicly.

Please subscribe to get the latest articles in your mailbox.

© 2017-2020 Python Circle   Contact   Sponsor   Archive   Sitemap