×

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

Crash Course on Python by Google

There is a new, free Python programming course offered by Google on Coursera. No programming experience is necessary. There are numerous Python courses available, but when you learn that Google is...

5 minutes read.

Python Dictionary items() method

Python Dictionary items() method The dictionary.items() method in Python returns a view object that displays a list of dictionary's (key, value) tuple pairs. Syntax dictionary.items() Parameter NA Return This method returns a view object, displaying the list...

1 minute read.

Python Comments

In this tutorial, we will discuss the importance of comments in the Python code and how various types of comments can be inserted in the code. Comments are used to describe...

3 minutes read.

Python System Requirements

Introduction As we know, Python is a popular programming language usually used to write scripts for operating systems. It’s handy adequate for utilizing in web development and application design. In this article,...

2 minutes read.

An Introduction to Subprocess in Python with Examples

Subprocess in Python By starting new processes, the Python function subprocess is utilized to run extra programs and applications. It makes it possible to run brand-new apps straight from a Programming...

6 minutes read.

Python for Data Analysis

Data analysis uses various techniques to read, illustrate, manipulate and evaluate a particular data. You can have access to the data and keep the data updated regularly. You can append...

4 minutes read.

How to Iterate a List in Python

As we know, a List is one of the four unique data structures available in Python; in this article, we will deep dive into understanding iterating through a list and...

3 minutes read.

How to Convert int to str in Python

How to Convert int to str in Python In the last article, we studied how we convert a variable with string datatype to integer datatype and discussed different data types available...

4 minutes read.

Palindrome In Python

What is Palindrome? A Palindrome can be defined as the number or a string that resides unchanged when it is reversed. Example: 14341 Output: Yes, this is a Palindrome number Example: RACECAR Output: Yes, this...

2 minutes read.

Syntax of Map function in Python

In this tutorial, we will understand what the map function in Python is meant. Further, we will see the syntax to be used for the same in python language. We...

3 minutes read.

FOO in Python

Python Programming Language: Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It...

3 minutes read.

Write Dictionary to CSV in Python

Python is an Object-Oriented high-level language. Python has an English-like syntax, which is very easy to read and write codes. Python is an interpreted language which means that it uses...

4 minutes read.

SKLearn Linear Module

The SK learn linear module is one such module that helps to study the relationship between the independent and dependent variables.The linear module can be implemented by using the best...

3 minutes read.

Python Set symmetric_difference() method

Python Set symmetric_difference() method The set.symmetric_difference() method returns a new set, which is the symmetric difference of two sets. The returned set contains only the unique items and, hence, deleting the common elements of...

2 minutes read.

Python Pass Statement

The pass statement is a null statement. The difference between pass and comment is that comment is ignored by the interpreter, whereas pass is not. The pass statement is typically used...

3 minutes read.

Standard GUI Unit Converter using PyQt5 in Python

GUI: A graphical interface (GUI) is a user interface that lets users interact with electronic devices like computers and smartphones by using menus, icons, and other visual cues (graphics). In contrast...

6 minutes read.

Python String endswith() method

Python String endswith() method The string.endswith() method in Python returns a Boolean value True if the string ends with the specified suffix, otherwise it returns False. Syntax endswith(suffix[, start[, end]]) Parameter suffix – This parameter represents a string or tuple...

2 minutes read.

Python Typing Module

An Introduction to the Typing Module The typing module is introduced in Python version 3.5 and used to provide hinting method types in order to support static type checkers and linters...

10 minutes read.

Convert string into int in Python

String A string is defined as a series of characters, special characters, and numbers. A string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements...

2 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.