# How to Write a Python Program to Check if a Year is a Leap Year or Not

A leap year is a year that contains an additional day added to keep the calendar year synchronized with the astronomical year or seasonal year. A year is a leap year if it is divisible by 4, unless it is a century year that is not divisible by 400 (1800 and 1900 are not leap years, 1600 and 2000 are leap years). In this blog post, we will discuss how to write a Python program that calculates whether a given year is a leap year or not.

• What is a leap year?
• Problem Statement
• Solution
• Explanation of Program Code
• MCQs with Answers

### What is a leap year?

As mentioned earlier, a leap year is a year that has one extra day, 366 days instead of the usual 365 days. This extra day is added to keep our calendar in sync with the Earth's orbit around the sun. Without leap years, our calendar would drift away from the actual seasons over time, leading to significant errors in our seasonal and astronomical events.

### Problem Statement:

Write a Python program that calculates whether a given year is a leap year or not.

### Solution:

To solve this problem, we can use the following algorithm:

1. Get the year from the user.
2. Check if the year is divisible by 4.
3. If the year is divisible by 4, check if it is a century year.
4. If the year is a century year, check if it is divisible by 400.
5. If the year is divisible by 400, it is a leap year.
6. If the year is not divisible by 400, it is not a leap year.
7. If the year is not divisible by 4, it is not a leap year.

Here is the Python program to calculate whether a given year is a leap year or not:

``````year = int(input("Enter a year: "))

if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print(year, "is a leap year")
else:
print(year, "is not a leap year")
else:
print(year, "is a leap year")
else:
print(year, "is not a leap year")``````

### Explanation of Program Code:

In this program, we first get the year from the user using the input() function. We then check if the year is divisible by 4 using the modulo operator (%). If the year is divisible by 4, we check if it is a century year by checking if it is divisible by 100. If the year is a century year, we check if it is divisible by 400. If the year is divisible by 400, it is a leap year. If the year is not divisible by 400, it is not a leap year. If the year is not a century year, it is a leap year. If the year is not divisible by 4, it is not a leap year.

### MCQs with Answers

What is a leap year?

A. A year that is divisible by 4

B. A year that is divisible by 100

C. A year that is divisible by 400

D. A year that is divisible by 4, unless it is a century year that is not divisible by 400

How is a century year determined in the leap year calculation?

A. By checking if it is divisible by 4

B. By checking if it is divisible by 100

C. By checking if it is divisible by 400

D. By checking if it is divisible by 100 and not divisible by 400

What is the Python concept used to solve the problem of determining whether a given year is a leap year or not?

A. Conditional statements

B. Loops

C. Functions

D. Variables

What is the output of the Python program to check whether a given year is a leap year or not, if the year is 2000?

A. 2000 is a leap year

B. 2000 is not a leap year

C. 2000 is a century year

D. 2000 is not a century year

Why is a leap year important?

A. It helps keep us in sync with the seasons

B. It adds an extra day to the year

C. It makes the year longer

D. It makes the calendar more accurate