Most people know that that we have a leap year every fourth year but that is not exactly accurate. To understand the properties of a leap year, you would want to look up some facts on leap year on math is fun.
The main properties of a leap year are
- it is evenly divided by 4 meaning no remainder
- if condition 1 passes, then it should not be evenly divisible by 100
- it is evenly divisible by 400
The Python function can look something like this
# This function checks if the year is a leap year
def leapYear(year):
# make sure the parameter is an integer
year = int(year)
# A year is a leap year if it is divisible by 400 or 4 and not by 100
if (year%400 == 0 or year%4 ==0) and year%100 !=0:
print(year,"is a leap year.")
else:
print(year,"is not a leap year.")
Share your thoughts