Software & Finance





Python - Check Leap Year





 

I have given here python program to check whether given year is a leap year or not.

This code is tested with Python version 2.6

 

        def IsLeapYear(year):
           if((year % 4) == 0):
              if((year % 100) == 0):
                 if( (year % 400) == 0):
                    return 1
                 else:
                    return 0
              else:
                 return 1
           return 0
        
        n = 0
        print "Program to check Leap Year"
        print "Enter Year: ", 
        n = input()
        if( IsLeapYear(n) == 1):
           print n, "is a leap year"
        else:
           print n, "is NOT a leap year"
        
		#sample output

		#Program to check Leap Year
		#Enter Year:  2012
		#2012 is a leap year

		#Program to check Leap Year
		#Enter Year:  1900
		#1900 is NOT a leap year

		#Program to check Leap Year
		#Enter Year:  2000
		#2000 is a leap year