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))
Output
CASE 1:

CASE 2:

Explanation: In this program, a user will be asked to enter a year to check it is a leap year or not and stored this input in a variable year. Next, we use if... statements to check the conditions for leap year. If the leap year's rule is satisfied, it will display the year is a leap. Else, it prints the year is not a leap year.