Questions
Write a python program to test whether a given year is leap year or not.
Last Updated : 12 Mar 2026
Jan 23
Solution:
# Get the year from the user
year = int(input("Enter any year: "))
# Check if the year is a leap year
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
# Year is a leap year
print("Leap year")
else:
# Year is not a leap year
print("Entered year is not Leap year")
OUPUT:
Enter any year 2024
leap year
Code Explaination:
-
Get Input:
year = int(input("Enter any year: "))
Reads and converts the year to an integer.
-
Leap Year Check:
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
Checks if the year is divisible by 400 or (divisible by 4 but not by 100).
-
Print Result:
print("Leap year")
Prints "Leap year" if true.print("Entered year is not Leap year")
Prints "Entered year is not Leap year" if false.
Meanwhile you can watch this video
Watch Video