Leap year in python

Python Program to get a year and check whether year is leap year or not.

Sample Input 1:

2016

Sample Output 1:

Leap year

Sample Input 2:

2017

Sample Output  2:

Not Leap Year

Program or Solution

				
				
					

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

if (year % 4) == 0:

   if (year % 100) == 0:

       if (year % 400) == 0:

           print("{0} is a leap year".format(year))

       else:

           print("{0} is not a leap year".format(year))

   else:

       print("{0} is a leap year".format(year))

else:

   print("{0} is not a leap year".format(year))

Program Explanation

Get input year from user using input() method,

All the years divisible by 4 are leap year except century years. Century years are leap year if it is divisible by 400.