Chessboard Color
Programming Basics · Python
TASK
Problem
Given chessboard cell `x y` from 1 to 8. Treat (1,1) as black. Print `BLACK` or `WHITE`.
EXAMPLE
Example
1 2
WHITE
LIMITS
Constraints
1 ≤ x,y ≤ 8
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `split()` separates one input line into individual values using spaces. `map()` applies the specified conversion to each input value. The `+` operator adds numbers. The `%` operator returns the remainder after division. Comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` compare values and produce `True` or `False`. `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 `'BLACK'` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Color depends on parity of the coordinate sum.']
ANSWER
Solution
+
x, y = map(int, input().split())
if (x + y) % 2 == 0:
print('BLACK')
else:
print('WHITE')