212k views
25 votes
Write a program for determining if a year is a leap year. In the Gregorian calendar system you can check if it is a leaper if it is divisible by 4 but not by 100 unless it is also divisible by 400.

1 Answer

7 votes

Answer:

def leap_year_check(year):

return if int(year) % 4 == 0 and (int(year) % 100 != 0 or int(year) % 400 == 0)

Step-by-step explanation:

The function is named leap_year_check and takes in an argument which is the year which we wish to determine if it's a new year or not.

int ensures the argument is read as an integer and not a float.

The % obtains the value of the remainder after a division exercise. A remainder of 0 means number is divisible by the quotient and a remainder other wise means it is not divisible by the quotient.

If the conditions is met, that is, (the first condition is true and either the second or Third condition is true)

the function leap_year_check returns a boolean ; true and false if otherwise.

User Tlwhitec
by
4.8k points