Write a program to check whether a year is leap year or not in Python

Here is an example program in Python that checks if the year entered by the user is a leap year or not:

year = int(input("Enter a year: "))

if year % 4 == 0:
  if year % 100 == 0:
    if year % 400 == 0:
      print(year, "is a leap year.")
    else:
      print(year, "is not a leap year.")
  else:
    print(year, "is a leap year.")
else:
  print(year, "is not a leap year.")

This program prompts the user to enter a year and then uses the modulo operator (%) to check if the year is evenly divisible by 4, 100, and 400. If the year is evenly divisible by 4, it is a leap year, unless it is also evenly divisible by 100, in which case it is not a leap year, unless it is also evenly divisible by 400, in which case it is a leap year.

Leave a Comment