WhatsApp and Telegram Group Card
WhatsApp Group Join Now
Telegram Group Join Now

Leap Year Program in Python

In this article of Leap Year Program in Python, we will see whether a entered year is a leap year or not. For checking a year we have knowledge of followings :-

  1. Operators.
  2. If-Else Statement.

A leap year is exactly divisible by 4 except for century years (years ending with 00) Like 400,800 etc.

Leap Year Program in Python

# To get year (integer input) from the user
year = int(input("Enter a 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(+year," is a leap 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(+year," is a leap year")

# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year
else:
    print(+year," is not a leap year")

Output :-

Enter a year : 2020
2020  is a leap year

Hope, after going through the whole article, all your doubts are cleared related leap year in python.

Also Read : Inheritance in Python – OOPS Concepts

Important Links

Join WhatsAppClick Here
Join TelegramClick Here
Join Twitter (X)Click Here
Join InstagramClick Here
Important Links