Skip to content
Home » Leap Year in Python using Function

Leap Year in Python using Function

Learn about Leap Year in Python using Function in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Leap Year in Python using Function

The below program checks whether the year is a leap year or not using the function.

# Python program to check year is a leap year or not using function

#user-defined function
def checkYear(year):   
    # check leap year or not
    if (year % 4) == 0:
        if (year % 100) == 0:
            if (year % 400) == 0:
                return True
            else:
                return False
        else:
             return True
    else:
        return False

# year input
year = int(input('Enter a year: '))

# function call
if(checkYear(year)):
    print('{0} is a leap year'.format(year))
else:
    print('{0} is not a leap year'.format(year))

Output:

Enter a year: 1996
1996 is a leap year

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Check Leap Year using nested if-else