Python Program to Check Leap Year
Python Program to Check Leap Year
Leap year: We all know that each year has 365 or 366 days. But whenever a year has 366 days, then the year is said to be a leap year. This extra day is always coming in February month that occurs after every four years. Hence leap year comes in every four years.
Rule to check a year is a leap or not
The following steps determine whether a year is a leap year or not:
- If a year is perfectly divisible by 4, leaving no remainder, the year will be a leap year. If it gives any reminder, then that year won’t be a leap year. For example, 1999 is not a leap year.
.
- If any year is perfectly divisible by 4 except for the year ending with 00 and perfectly divisible by 100, then the year won’t be a leap year. For example, 1900 is not a leap year.
- If any year is ending with 00 and perfectly divisible by 400, then the year will be a leap year. For example, 2000 is a leap year.
Source Code
The following is a source code to check leap year:
#Program to check if a given year is a leap or not
#Years to be checked
year = int(input(“Enter the year to be checked:”))
#Check the condition
if(year % 4)==0:
if(year % 100)==0:
if(year % 400)==0:
print(“{0} is a leap year”.format(year))
else:
print(“{0} is not a leap year”.format(year))
else:
print(“{0} is a leap year”.format(year))
else:
print(“{0} is not a leap year”.format(year))