Python program to check a year is a leap year or not. Below is a code snippet,
# To check if the year is a leap year or not in Python
year = int(input("Enter a year to check : "))
if ((year % 4) == 0 and (year % 100) != 0) or ((year % 400) == 0):
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
Output 1:
Enter a year to check: 2020
2020 is a leap year
Output 2:
Enter a year to check: 2021
2021 is not a leap year
Comments (0)