;

Python Program to Check Whether the Year is a Leap Year or Not


Tutorialsrack 22/04/2020 Python

In this Python program, we will learn how to check whether the year is a leap year or not. 

What is a Leap Year?

A leap year is a calendar year that contains an additional day added to keep the calendar year synchronized with the astronomical year or seasonal year. Leap year is a year that is exactly divisible by four, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the year  2007, 2009, 2011 is not a leap year but the years 1600, 2000 and 2020 are the leap years.

Here is the source code to check if the year is a leap year or not.

Python Program to Check Whether the Year is a Leap Year or Not
# Python Program to Check Whether the Year is a Leap Year or Not

# To get year (integer input) from the user
year = int(input("Enter a year: "))

if (year % 4) == 0:
   if (year % 100) == 0:
       if (year % 400) == 0:
           print("\n{0} is a leap year".format(year))
       else:
           print("\n{0} is not a leap year".format(year))
   else:
       print("\n{0} is a leap year".format(year))
else:
   print("\n{0} is not a leap year".format(year))
Output

Enter a year: 2020

2020 is a leap year

 

Enter a year: 2021

2021 is not a leap year


Related Posts



Comments

Recent Posts
Tags