Python 3 Program to Check Leap Year

0
124

python 3 program check leap year

In this tutorial, you will find a simple Python 3 program to check leap year. To understand this program, you should have a basic understanding of Python variables, operators, and if-else statements. In case, you are just getting started with Python, then I will recommend you to get any of these Python books for beginners.

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.

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 completely 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)

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