FREE E LEARNING PLATFORM
HOMEEXCEPTIONSOOPSJVMINTRO
 

Python Program to Check whether Year is a Leap Year or not




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

Enter Year:2004
2004 is a Leap Year






Leave Comment