Articles

Python program to check if a year is a leap year

Python program to check if a year is a leap year


In this python programing guide, we are going to learn about

  • python program to check if a year is a leap year

Program to check a Leap Year in Python

The python program to check a leap year is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

year = int(input("Enter year: "))

if year % 4 == 0:
   if year % 100 == 0:
       if year % 400 == 0:
           print("{} is a Leap Year!".format(year))
       else:
           print("{} is not a Leap Year!".format(year))
   else:
       print("{} is a Leap Year!".format(year))
else:
   print("{} is not a Leap Year!".format(year))

The output of program to check a leap year in python is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter year: 2020
2020 is a Leap Year!

Few important tips about this program

1. A leap year is always divisible by 4 or by 400.

2. We used to format() function here to beautify the output on the screen.

 

Snapshot for how to write a program to check leap year in python:

write a program to check if the year entered by the user is a leap year or not in python

 


Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Feb 14,2021  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!