codescracker


python

Python Program to Check Leap Year or Not



« Previous Program Next Program »


Check Leap Year or Not in Python

To check whether the given year is a leap year or not a leap year in python, you have to ask from user to enter a year to check for leap year as shown in the program given here.

Python Programming Code to Check Leap Year or Not

Following python program ask from user to enter year to check whether it is a leap year or not:

# Python Program - Check Leap Year or Not
		
while True:
	print("Enter 'x' for exit.")
	num = input("Enter year: ")
	if num == 'x':
		break
	try:
		year = int(num)
	except ValueError:
		print("Please, enter year...")
	else:
		if((year%4 == 0) and (year%100 != 0)):
			print(year, "is a Leap Year.\n")
		elif(year%100 == 0):
			print(year, "is not a Leap Year.\n")
		elif(year%400 == 0):
			print(year, "is a Leap Year.\n")
		else:
			print(year, "is not a Leap Year.\n")

Here is the sample run of the above Python program demonstrating how to check for leap year:

python check leap year

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test