Page Contents

In this tutorial we will write a Python program for display all leap years from 1900 to 2101 . Before reading further we recommend to read about following articles –

## What is leap year ?

Generally a year has 365 days but a leap year has 366 days . A year will be said a leap year if the year fulfills the below conditions-

- The year should be divisible by 400
- The year should be divisible by 4 but not by 100

#### Example :

- 2000 is a leap year as it is divisible by 400
- 2004 is a leap year as it is divisible by 4
- 2100 is not a leap year because it is divisible by 4 and 100 .

## Python program to check if a year is leap year or not

#### Steps:

- First we will check if the year is divisible by 400 or not . If the year is divisible by 400 we will print the year is a leap year
- Then we will check if the year is divisible by 4 and not divisible by 100 . If the year fulfills this condition then we will print the year is a leap year
- otherwise we will print the year is not a leap year

```
year=2100
# checking if the year divisible by 400 or not
if year%400==0:
print(year,"is a leap year")
# checking if the year divisible by 4 and not by 100
elif year%4==0 and year%100!=0:
print(year,"is a leap year")
else:
print(year,"is not a leap year")
```

2100 is not a leap year

As 2100 is divisible by 4 and by 100 so it is not a leap year .

## Python program for display all leap years from 1900 to 2101

#### Steps:

- First we will initialize
`start`

and`end`

variable with the start year and end year . - After that we will initialize an empty list .
- Then we will traverse from
`start`

to`end`

and check which year is a leap year . If any year is a leap year then it will be appended to the empty list - At last the list will be printed .

```
start=1900
end=2101
years=[]
for year in range(start,end+1):
if year%400==0:
years.append(year)
elif year%4==0 and year%100!=0:
years.append(year)
print(years)
```

[1904, 1908, 1912, 1916, 1920, 1924, 1928, 1932, 1936, 1940, 1944, 1948, 1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036, 2040, 2044, 2048, 2052, 2056, 2060, 2064, 2068, 2072, 2076, 2080, 2084, 2088, 2092, 2096]

## Python program to print all leap years between two given years

#### Implementing the above code defining a function

```
def is_leap_year(year):
if year%400==0:
return True
# checking if the year divisible by 4 and not by 100
elif year%4==0 and year%100!=0:
return True
else:
return False
def leap_years_in_between_two_years(startYear,endYear):
years=[]
for year in range(startYear,endYear+1):
if is_leap_year(year):
years.append(year)
return years
print(leap_years_in_between_two_years(1900,2101))
print(leap_years_in_between_two_years(2000,2010))
```

[1904, 1908, 1912, 1916, 1920, 1924, 1928, 1932, 1936, 1940, 1944, 1948, 1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036, 2040, 2044, 2048, 2052, 2056, 2060, 2064, 2068, 2072, 2076, 2080, 2084, 2088, 2092, 2096] [2000, 2004, 2008]

**Thank you for reading this Article . If You enjoy it Please Share the article . If you want to say something Please Comment **.

I have seen a great deal of useful things on your internet site about pcs. However, I’ve the judgment that notebook computers are still more or less not powerful adequately to be a good choice if you typically do tasks that require lots of power, just like video editing. But for net surfing, word processing, and majority of other common computer functions they are okay, provided you don’t mind the small screen size. Many thanks for sharing your opinions.

I’m truly enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme? Superb work!