Learn about Leap Year Code in Python using Calendar Module in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Leap Year Code in Python using Calendar Module
The function isleap()
in calendar Module in python checks whether the given year is a lear year or not. The below code explains whether the given year is a leap year or not using Calendar Module.
Source code:
# Python program to check leap year or not using calender
# calendar module
import calendar
#function
def checkYear(year):
return(calendar.isleap(year))
# take input
year = int(input('Enter a year: '))
# function call and display result
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: 2016
2016 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 : Leap Year in Python using Function