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.
As the founder and passionate educator behind this platform, I’m dedicated to sharing practical knowledge in programming to help you grow. Whether you’re a beginner exploring Machine Learning, PHP, Laravel, Python, Java, or Android Development, you’ll find tutorials here that are simple, accessible, and easy to understand. My mission is to make learning enjoyable and effective for everyone. Dive in, start learning, and don’t forget to follow along for more tips and insights!. Follow him