Beginner · Conditions · 65 of 264
Which quadrant?
Read a point (x, y) where neither coordinate is 0, and print its quadrant: 1 for x > 0 and y > 0, 2 for x < 0 and y > 0, 3 for both negative, 4 for x > 0 and y < 0.
Input: x and y, one per line. Output: 1, 2, 3 or 4
Examples
Input
3 4
Output
1
Input
-3 4
Output
2
Input
-1 -1
Output
3
One more test checks 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.