×

Python Program to Check Leap Year

Python Program to Check Leap Year

Leap year: We all know that each year has 365 or 366 days. But whenever a year has 366 days, then the year is said to be a leap year. This extra day is always coming in February month that occurs after every four years. Hence leap year comes in every four years.

Rule to check a year is a leap or not

The following steps determine whether a year is a leap year or not:

  • If a year is perfectly divisible by 4, leaving no remainder, the year will be a leap year. If it gives any reminder, then that year won’t be a leap year. For example, 1999 is not a leap year.

.

  • If any year is perfectly divisible by 4 except for the year ending with 00 and perfectly divisible by 100, then the year won’t be a leap year. For example, 1900 is not a leap year.
  • If any year is ending with 00 and perfectly divisible by 400, then the year will be a leap year. For example, 2000 is a leap year.

Source Code

The following is a source code to check leap year:

 #Program to check if a given year is a leap or not     
 #Years to be checked     
 year = int(input("Enter the year to be checked:"))           
 #Check the condition     
 if(year % 4)==0:            
     if(year % 100)==0:   
         if(year % 400)==0:      
             print("{0} is a leap year".format(year))   
else:      
             print("{0} is not a leap year".format(year))   
else:         
         print("{0} is a leap year".format(year))             
 else:   
     print("{0} is not a leap year".format(year))  

Output

CASE 1:

Python Program to Check Leap Year

CASE 2:

Python Program to Check Leap Year

Explanation: In this program, a user will be asked to enter a year to check it is a leap year or not and stored this input in a variable year. Next, we use if... statements to check the conditions for leap year. If the leap year's rule is satisfied, it will display the year is a leap. Else, it prints the year is not a leap year.


Related Topics

Accuracy_score Function in Sklearn

A crucial stage in data science is measuring our model's performance using the appropriate metric. In this article, we will examine two methods for calculating the accuracy of your predictions:...

13 minutes read.

Joint Plot in Python

Introduction to Joint plots: The joint plot is the finest approach to evaluate both the specific distribution of each variable and also the connection between the two variables. Three different plots make...

4 minutes read.

Python Set discard() method

Python Set discard() method The set.discard() method in Python removes a specified element from the set (if present). Syntax set.discard(value) Parameter value- This parameter represents the element to be removed from the set. Return None Example 1 # Python program explaining # the...

1 minute read.

Python program to count the number of a substring in a string

Python program to count the number of a substring in a string A part of the string is called a substring. This article explains the Python program to find how many...

1 minute read.

Python Parser

Introduction : Parsing is referred to as the processing and translation of a Python program into machine language. In general, we could indeed say that the command parse is used to...

4 minutes read.

Python NewLine

In python, a new line character denoted by "\n" is known as an escape character or escape sequence, and it will force the cursor to change its position to the next...

6 minutes read.

How to Install Pandas in Python?

Pandas is a library created in Python for handling and analyzing data. Pandas provides a variety of procedures and data structures for manipulating time series and numerical data.  Pandas is...

3 minutes read.

Function annotations() in Python

What is Function Annotations? Function annotations provide a way related to different parts of a function at compile time with arbitrary Python expressions. It doesn’t have life in Python runtime execution....

3 minutes read.

Python String rindex() method

Python String rindex() method The string. rindex() method in Python returns the highest index of the substring inside the string (if found). If the substring is not found, it raises an...

2 minutes read.

Python Function

Python Function A Python function is a reusable, organized block of code that is used to perform the specific task. The functions are the appropriate way to divide an extensive program into a...

7 minutes read.

Python Random shuffle( ) method

The shuffle() is used to change the positions of the elements in the mutable sequences. The shuffle( ) function will change the positions of the elements in the sequence of...

3 minutes read.

Python String isalpha() method

Python String isalpha() method The string.isalpha () method in Python returns a boolean value true if all characters in the  string are alphabetic else for any other value it returns false. Syntax isalpha()  Parameter NA Return This...

1 minute read.

How to set font for Text in Python

As a tuple with the font family as the first component, a size in point as the second, and possibly a string with one or more of the style modifiers...

5 minutes read.

Python map() function

Python map() function The map() function in Python returns an iterator that applies a function to every item of iterable, yielding the results. Syntax map(function, iterable, ...) Parameter function: It is a required parameter that represents the function to...

1 minute read.

Shallow Copy and Deep Copy in Python

Shallow Copy and Deep Copy in Python In this section, we will learn about the Shallow Copy and Deep Copy in the Python program. But before going through the topic, we...

6 minutes read.

Python Os sep

Python: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

3 minutes read.

SKLearn Clustering

These are ml methods thatare responsible for detecting patterns and the similarities within the data.The clustering methods are unsupervised.Here the data is clustered to form groups with the help of...

3 minutes read.

Python Parallel Processing

By performing more jobs concurrently, your software may complete more tasks in a shorter amount of time. These aid in solving major issues. The following subjects will be covered in...

2 minutes read.

Python Kwargs Example

In this article, we'll talk about Python's kwargs notion. In Python, kwargs has two stars and passes a variable number of keyworded argument lists to the function, whereas args has...

5 minutes read.

Polymorphism in Python

What is polymorphism and why is it important? Polymorphism's literal definition is the state of occurring in diverse shapes or forms. When it comes to programming, the idea of polymorphism is crucial....

3 minutes read.