Python Program to Check Leap Year

Python program to check leap year; Through this tutorial, i am going to show you how to check leap year in python.

In this tutorial, i will write two program to check leap year in python.

Python Program to Check Leap Year

  • Python program to check whether a given year is a leap year or not
  • Python program to check leap year using function

Python program to check whether a given year is a leap year or not

# Python program to check the given year is leap or not
n = input("Please enter year")
year = int (n)
if (( year%400 == 0)or (( year%4 == 0 ) and ( year%100 != 0))):
    print("%d is a Leap Year" %year)
else:
    print("%d is Not the Leap Year" %year)

Output

Please enter year 2021 
2021 is Not the Leap Year 

2: Python program to check leap year using function

# Python program to check the given year is leap or not 
# using math calender module in Python
#here import calender module
import calendar
n = input("Please enter year")
year = int (n)
# calling isleap() method to check for Leap Year
val = calendar.isleap(year)
if val == True: 
  print("% s is a Leap Year" % year)  
else:
  print("% s is not a Leap Year" % year)

Output

Please enter year 2019 
2019 is not a Leap Year  

Recommended Python Tutorials

Recommended:-Python Map() Method

Leave a Comment