Python Program to Check Leap Year – 2022

Machine Learning Projects

Hey guys, in this blog we will see a Python Program to Check Leap Year.

Code

# Python Program to Check Leap Year

year = input('Input the year -> ')

year = int(year)


# divided by 100 means century year (ending with 00)
# century year divided by 400 is leap year
if (year % 400 == 0) and (year % 100 == 0):
    print("{0} is a leap year".format(year))


# not divided by 100 means not a century year
# year divided by 4 is a leap year
elif (year % 4 ==0) and (year % 100 != 0):
    print("{0} is a leap year".format(year))


# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year
else:
    print("{0} is not a leap year".format(year))

Output

Input the year -> 2024
2024 is a leap year
Input the year -> 2023
2023 is not a leap year
Input the year -> 2021
2021 is not a leap year

So here we are checking 2 conditions for a year to be a leap year:

  1. It should be fully divisible by 400 and 100 both to be a Leap Year.
  2. Or if it is fully divisible by 4 and not by 100 then also it is a Leap Year.

Check out our other python programming examples

Leave a Comment

Your email address will not be published.