Beginner · Conditions · 59 of 264
Leap year
A year is a leap year if it divides by 4, except years that divide by 100, which are leap years only if they also divide by 400.
Input: a year. Output: leap or not leap
Examples
Input
2024
Output
leap
Input
2023
Output
not leap
Input
2000
Output
leap
Input
1900
Output
not leap
2 more tests check other inputs when you press Check.
Stuck? The idea behind conditions
An if statement runs its indented lines only when the condition is true; elif tries another condition; else catches everything left.
Compare with == (equal), != (not equal), <, <=, >, >=, and join conditions with and, or, not.
n = int(input())
if n > 0:
print("positive")
elif n < 0:
print("negative")
else:
print("zero")Watch for: = gives a value, == compares. And the order of elif matters: the first true one wins, so test the narrow case first.