In this article let's learn how to check if a number is a leap year or not. A number is said to be a leap year if it is having an extra day on February 29 that is the number of days in a year is 366.
Leap year occurs once in 4 years. non leap year will contain 28 days in February and have 365 days in a year
Leap year occurs once in 4 years. non leap year will contain 28 days in February and have 365 days in a year
There is a rule to check whether a number is a leap year or not
First check if number is completely divisible by 4 and not by hundred
Secondly check if number is completely divisible by 400
If either one of the above two statements are true then the number is said to be a leap year.
leap_year = ((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0)
Let us use above rule to write a program to check leap year in python
year = int(input("Enter a Year : "))
if ((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0):
print("Its Leap Year")
else:
print("It's not a Leap Year")
OUTPUT 1:
Enter a Year : 2002
It's not a Leap Year
OUTPUT 2:
Enter a Year : 2011
It's not a Leap Year
OUTPUT 3:
Enter a Year : 3033
It's not a Leap Year
Conclusion : try the program by yourself and comment down below if you have any queries
0 Comments