In this tutorial, we’ll write a leap year program in python to check whether the input year is a leap year or not. Before we enter Python leap year programs, Let’s see the Python Leap Year’s definition and logic.
We’ll be covering the following topics in this tutorial:
How to Calculate Leap Year
The year includes 365 days, but the leap year includes 366 days. This extra day in the leap year is included in February. Logically, the year perfectly divisible by four is known as Leap year except for the century decades.
Century years imply they end with 00 such as 1200, 1300, 2400, 2500, etc. (Clearly, they’re divisible by 100).
A leap year happened once every four decades.
A year is a leap year when the following requirements are satisfied:
• A leap year is exactly divisible by 4, but not by 100. For example, 2012 is a leap year.
• If a year is divisible by 100, but not by 400. For example, 1900 is not a leap year.
• If a year is divisible by both, then it is a leap year.
• The century year is a leap year only if it is perfectly divisible by 400. For example, 2000 is a leap year.
Python Program to Check Leap Year
#In this leap year python program, the user to asked enter a year. The program checks whether the entered year 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("{0} is a leap year".format(year)) else: print("{0} is not a leap year".format(year)) else: print("{0} is a leap year".format(year)) else: print("{0} is not a leap year".format(year))
Output: