Python Program - Check Leap Year

w‮.ww‬theitroad.com

To check if a year is a leap year or not, we need to follow the following steps:

  • A year is a leap year if it is divisible by 4 and not divisible by 100, or if it is divisible by 400.

Here's a Python program that checks if a year is a leap year or not:

# Get the input from the user
year = int(input("Enter the year: "))

# Check if the year is a leap year
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
    print(year, "is a leap year")
else:
    print(year, "is not a leap year")

In this program, we first get the input year from the user using the input() function. We then use the if statement to check if the year is divisible by 4 and not divisible by 100, or if it is divisible by 400. If the year satisfies either of these conditions, we print that it is a leap year. Otherwise, we print that it is not a leap year.