Leap Year
Programming Basics · Python
TASK
Problem
Given `year`, print `YES` if it is leap: divisible by 400, or divisible by 4 but not by 100.
EXAMPLE
Example
2024
YES
LIMITS
Constraints
year ≥ 1
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `int()` converts a numeric string into an integer. The `%` operator returns the remainder after division. Comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` compare values and produce `True` or `False`. `and` requires all combined conditions to be true. `or` requires at least one condition to be true. `if` checks a condition and runs its block when the condition is true. `else` runs when the corresponding `if` condition is false. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** The `%` operator returns a division remainder. Therefore `n % k` is useful for divisibility checks and for working with the last digits of a number. The expression `'YES'` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Translate the rule directly with `or` and `and`.']
ANSWER
Solution
+
y = int(input())
if y % 400 == 0 or (y % 4 == 0 and y % 100 != 0):
print('YES')
else:
print('NO')