how to write leap year program in python? – leap year program in python

In this post, we will write a Python program to check whether the input year(entered by user) is leap year or not also you know A leap year occurred once every 4 years.

Python Program to Check whether Year is a Leap Year or not

in a year or an year, A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year is a leap year only if it is perfectly divisible by 400. For example,


2017 is not a leap year
1900 is a not leap year
2012 is a leap year
2000 is a leap year

Also You can Learn My python program

Read Also:  Python Array Contains: How To Check If Item Exists In Array?

Example 1: Source Code

In this python program, user is asked to enter a year like as a year is a 2000. Program checks whether the entered year is leap year or not.

# Python program to check if year is a leap year or not
# User enters the year
year = 2000

# To get year (integer input) from the user
# year = int(input("Enter a year: "))

# Leap Year Check
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))

Results:

Read Also:  How to check if a variable exists in Python?

2000 is a leap year

You can update the value of year in the python source code and execute it again to demo as well as testing purpose this python program.