script program   0   34
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:

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 and run using the command python3

script program   0   34

Related Articles:
Python Script 3: Validate, format and Beautify JSON string Using Python
Validating json using python code, format and beautify json file using python, validate json file using python, how to validate, format and beautify json...
Python Script 10: Collecting one million website links
Collecting one million website links by scraping using requests and BeautifulSoup in Python. Python script to collect one million website urls. Using beautifulsoup to scrape data...
Python Script 6: Wishing Merry Christmas using Python Turtle
Python script to wish merry Christmas using python turtle. Using Python Turtle module to wish merry Christmas to your friends....
Python Script 1: Convert ebooks from epub to mobi format
Python script to convert the ebooks from one format to another in bulk. Automated book conversion to kindle format. Free kindle ebook format conversion....

Please subscribe to get the latest articles in your mailbox.

Recent Posts:

© 2018-2019