27. Python Program to Check Whether the Given Year is Leap Year or Not.
How does this program work?
- In this program you are going to learn about to check if a year is leap year or not using Python.
- In this program A year is leap if it is perfectly divisible by 4 and 400.
- When the year is divided by 4 and 400, we use the remainder operator % to compute the remainder.
- If the remainder is zero, the year is leap year else the year is not a leap year.
Here is the code
yr = int(input("Enter the year: "))
if yr % 4 == 0:
if yr % 100 == 0:
if yr % 400 == 0:
print("Leap year")
else:
print("Not a leap year")
else:
print("Leap year")
else:
print("Not a leap year")