How to find whether a given year is a leap year or not using Python?

In this Python tutorial, we will learn how to find if a year is a leap year or not in Python.

Find whether a given year is a leap year or not using Python

Leap Year (LY) is a year which satisfies the following conditions:

  • The year should be divisible by 4.
  • The year should be divisible by 4 even if it is divisible by 100.
  • Therefore, 2000 is a LY but 2100 is not.
  • So, the next century LY will be 2400.

leap year python identify
The above concept is easily explained in the below picture.



Leap year python

Let’s take a look at the code snippet.

Program:

year=int(input("Input the Year: "))               #input year 
if(year%4==0):                                    #check whether year is divisible by 4 or not
    if(year%400==0):                              #if year is divisible by 400 
        print("Entered Year is a Leap Year.")     
    elif(year%100==0 and year%400!=0):
        print("It is not a Leap Year.") #if divisible by 100 but not 400
    else:
        print("Entered Year is a Leap Year.")
else:
    print("Entered Year is not a Leap Year.")

Output 1:

Input the Year: 2008
Entered Year is a Leap Year.

Output 2:

Input the Year: 2100
Entered Year is not a Leap Year.

Also Read:

Leave a Reply

Your email address will not be published. Required fields are marked *