Blog
Checking Leap Year!
- Harshit
- September 13, 2020
- 7:07 am
- No Comments
A simple code to check whether the given year is leap year or not.
Welcome to the code! Here’s a simple code to check whether the given year by the user is a leap year or not.
Condition for a leap year:
- A leap year is exactly divisible by 4 except for century years (years ending with 00).
- The century year is a leap year only if it is perfectly divisible by 400.
In this code, the user is asked for a year and the given year will be checked to know whether the given year is a leap year or not using the python code.
Note: Loved the post? You too can publish your article on “Python for fun” which will be loved by millions. Contribute an article!
year = int(input("Enter the year to check: "))
if year % 4 == 0 and year % 100 != 0:
print(year, "is a leap year")
elif year % 100 == 0:
if year % 400 == 0:
print(year, "is a leap year")
else:
print(year, "is not a leap year")
else:
print(year, "is not a leap year")
5
1
vote
Rating
Subscribe
Login
0 Comments
Inline Feedbacks
View all comments