Friday, July 6, 2012

Check the year is Leap year or not in Python

open a python script editor and just paste the following code in your new python(.py or .pyw) file -

def verifyLeapYear ():
    year = 2016
    print year
    if (year % 4 == 0) & (year % 100 != 0) | (year % 400 == 0):
        print "The " + str(year) + " is a Leap Year"
    else:
        print "The " + str(year) + " is not a Leap Year"
   
verifyLeapYear()


output is-

No comments:

Post a Comment