Program to Check Leap year in Python
In this program we are going to test whether a given year is a leap year or not.
Leap year is the year which is divisible by 4 except the century year that is ending with 00.
The century year is the leap year only if it is perfectly divisible by 400.
For example:
2017 is not a leap year.
2000 is a leap year.
Algorithm:
- Input the year from the user.
- Check using if statements , whether it is a leap year or not.
- Print the final result
- Exit
Code:
n= int(input("Enter the year you want to check?"))
if (n%4==0):
if (n%100==0):
if (n%400==0):
print("It is a leap year")
else:
print("It is not a leap year")
else:
print("It is a leap year")
else:
print("It is not a leap year")
Output:
Enter the year you want to check? 1996
It is a leap year
Enter the year you want to check? 1900
It is not a leap year
Report Error/ Suggestion