Wednesday, October 4, 2023
HomeProgrammingPythonPython 3 Program to Check Leap Year

Python 3 Program to Check Leap Year

This post was last Updated on June 8, 2023 by Himanshu Tyagi to reflect the accuracy and up-to-date information on the page.

In this tutorial, you will find a simple Python 3 program to check leap year. It would be best to understand this program if you understood Python variables, operators, and if-else statements.

Python Program to Check Leap Year

To check if a number is a leap year, it should follow these conditions:

1. The year should be completely divisible by 4.

2. The year should be utterly divisible by both 100 and 400.

Now, in the Python code, you can take year input from the user and see its divisibility by using nested if-else statements.

year = int(input("enter the year: "))
if year % 4 == 0:
   if year % 100 == 0:
       if year % 400 == 0:
           print('%0.0f is a leap year' % year)
       else:
           print('%0.0f is not a leap year' % year)
   else:
       print('%0.0f is a leap year' % year)
else:
       print('%0.0f is not a leap year' % year)

Other Python 3 Programs:

  1. Python 3 Program to Generate A Random Number.
  2. Python 3 Program To Swap Two Numbers.
  3. Python 3 Program To Solve A Quadratic Equation.
  4. Python 3 Program to Calculate The Area of a Triangle.
  5. Python 3 Program to Find the Square Root of A Number.

Output

python check leap year

Download Python Program.

Other Python Programs:

  1. Python 3 Program to Check if a Number is Positive, Negative, or 0.
  2. Python 3 Program To Convert Celsius To Fahrenheit.
  3. Python 3 Program To Find the Largest Element In An Array or List.
  4. Python 3 Program To Find The Sum of An Array.
  5. Python 3 Program to Convert Kilometers to Miles.
Himanshu Tyagi
Himanshu Tyagi
Hello Friends! I am Himanshu, a hobbyist programmer, tech enthusiast, and digital content creator. Founder Cool SaaS Hunter. With CodeItBro, my mission is to promote coding and help people from non-tech backgrounds to learn this modern-age skill!
RELATED ARTICLES