Home » Python » Python programs

# Python program to check the given year is a leap year or not

**Leap year check in Python**: Here, we will learn **how to check a given year is a leap year or not in Python programming language?**

Submitted by Bipin Kumar, on December 10, 2019

A **leap year** is a year that is completely divisible by 4 except the century year (a year that ended with 00). A century year is a leap year if it is divisible by 400. Here, a year is provided by the user and we have to check whether the given year is a leap year or not. This problem, we will solve in two ways first by using the calendar module and second by simply checking the leap year condition.

### 1) By using the calendar module

Before going to solve the problem, initially, we learn a little bit about the calendar module. Calendar module is inbuilt in Python which provides us various functions to solve the problem related to date, month and year.

**Program:**

# importing the module import calendar # input the year year=int(input('Enter the value of year: ')) leap_year=calendar.isleap(year) # checking leap year if leap_year: # to check condition print('The given year is a leap year.') else: print('The given year is a non-leap year.')

**Output**

RUN 1: Enter the value of year: 2020 The given year is a leap year. RUN 2: Enter the value of year: 2021 The given year is a non-leap year.

### 2) By simply checking the leap year condition

As we know the condition to check the given year is a leap year or not. So, here we will implement the condition and try to write the Python program.

**Program:**

# input the year y=int(input('Enter the value of year: ')) # To check for non century year if y%400==0 or y%4==0 and y%100!=0: print('The given year is a leap year.') else: print('The given year is a non-leap year.')

**Output**

RUN 1: Enter the value of year: 2020 The given year is a leap year. RUN 2: Enter the value of year: 2000 The given year is a leap year.

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.