Today we will discuss how to know which year is leap or February is 29 days in Python. Basically a year have 365 days, each leap year have 366 days because additional day is added to February which is 29 days.
To able coding program we should know how algorithm work behind the scene. Please check below concept before write code.
Leap year is not satified condition as below
To implement this algorithm you have to understand following Python basic:
Look at below example snippet below to understand:
Example #1 - Using Algorithm
# Suppose user input 1900 as year to check
year = 1900
if (year % 4) == 0 and (year % 400) == 0:
print(year,"is a leap year")
else:
print(year,"is not a leap year")
Output:
1900 is not a leap year
Example #2 - Using Module Calendar
# using module
import calendar
# Suppose user input 1900 as year to check
year = 2024
if calendar.isleap(year):
print(year,"is a leap year")
else:
print(year,"is not a leap year")
Output:
2024 is a leap year
Hope you learn something in this page. Thank you.
Founder of CamboTutorial.com, I am happy to share my knowledge related to programming that can help other people. I love write tutorial related to PHP, Laravel, Python, Java, Android Developement, all published post are make simple and easy to understand for beginner. Follow him