Python program to print leap years between two given years

Dear Reader, In this post I am going to write a core Python program to print Leap years!.

First, we will get the start and end year from the user and then print the leap years between the start and the end year.

Here is the complete python program to find leap year between two given years:

#Print a string about the program
print ("Print leap year between two given years")
#Get the input start and end year from user
print ("Enter start year")
startYear = int(input())
print ("Enter last year")
endYear = int(input())

print ("List of leap years:")
#loop through between the start and end year
for year in range(startYear, endYear):
  #check if the year is a Leap year if yes print
  if (0 == year % 4) and (0 != year % 100) or (0 == year % 400):
    print (year)

Sample output of the above program:

Print leap year between two given years
Enter start year
1996
Enter last year
2016
List of leap years:
1996
2000
2004
2008
2012

Read the inline comments in the python snippet to understand it.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top