Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A year is a leap year if it is divisible by . But a century year (divisible by ) is a leap year only if it is also divisible by . Write the condition. Which of , and are leap years?
and comes before or. Use brackets to say what you mean.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
The condition. Divisible by 4, and (not a century, or divisible by 400):
year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
Note. The brackets matter. Without them, and is worked out before or, and the answer would be wrong.
Log in to join the discussion.
Loading…