In this post, we will write a Python program to check whether the input year(entered by user) is leap year or not.
Python Code
In this program, user is asked to enter a year. Program checks whether the entered year is leap year or not.
# User enters the year year = int(input("Enter Year: ")) # Leap Year Check if year % 4 == 0 and year % 100 != 0: print(year, "is a Leap Year") elif year % 100 == 0: print(year, "is not a Leap Year") elif year % 400 ==0: print(year, "is a Leap Year") else: print(year, "is not a Leap Year")
Output:
Sohaib says
A bit correction required in the code. It’s displaying incorrect result for 1600/2000 etc.
#Correct code
# User enters the year
year = int(input(“Enter Year: “))
# Leap Year Check
if year % 4 == 0 and year % 100 != 0:
print(year, “is a Leap Year”)
elif year % 400 ==0:
print(year, “is a Leap Year”)
elif year % 100 == 0:
print(year, “is not a Leap Year”)
else:
print(year, “is not a Leap Year”)