Program to check leap year or not in python

Program to check leap year or not in python


A number is said to be a leap year if the number is divisible by 4 but not by 100 then, it is a leap year. Also, if a number is divisible by 4, 100 and 400 then it is a leap year. If the above conditions does not satisfy then the year is not a leap year.
Example: 2000,2012 etc.,


Program:


/*Python program to check the given number is a leap year or not*/

def check_Year(yr): if (yr % 4) == 0: if (yr % 100) == 0: if (yr % 400) == 0: return True else: return False else: return True else: return False yr = 2000 if(check_Year(yr)): print("It is a Leap Year") else: print("It is not a Leap Year")

Output:

It is a Leap year


def is a keyword used to define user-defined functions, here check_Year(yr) is the user defined
function which is used to check the given number is leap year or not ,if it is a leap year returns
True else returns False. If it returns True then the output will be 'It is a Leap Year else the output
will be It is not a Leap year.





Post a Comment

0 Comments