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:
- Python 3 Program to Generate A Random Number.
- Python 3 Program To Swap Two Numbers.
- Python 3 Program To Solve A Quadratic Equation.
- Python 3 Program to Calculate The Area of a Triangle.
- 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)