Python program to check if a year is leap year or not

Python 3 program to check if a year is leap year or not :

To check if a year is leap year or not, we need to check if it is divisible by 4 or not. A year is leap year if it is divisible by 4 and for century years, if it also divisible by 400. Following algorithm we are using in the example program :

Steps to check if a year is leap year or not :

1. Check if it is divisible by 4. If not than it is not a leap year.
2. If divisible by 4, check if it is divisible by 100. If not , it is not a century year, so it is a leap year.
3. If divisible by 100, check if it is divisible by 400 or not. If yes it is a leap year, else not.

List of leap years from 1900 to 2020 are : 1904, 1908, 1912, 1916, 1920, 1924, 1928, 1932, 1936, 1940, 1944, 1948, 1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020 . You can verify with the following example :

Program :

def printLeapYear():
	print("Inpur Year is a Leap Year")

def printNotLeapYear():
	print("Inpur Year is not a Leap Year")


input_year = int(input("Enter a Year : "))

if input_year % 4 == 0:
	if input_year % 100 == 0 :
		if input_year % 400 == 0 :
			printLeapYear()
		else :
			printNotLeapYear()
	else :
		printLeapYear()
else :
	printNotLeapYear()

Sample Output :

Enter a Year : 2000
Inpur Year is a Leap Year

Enter a Year : 2001
Inpur Year is not a Leap Year
Sitewide-USD 336x280

Leave a Reply