Source: Kattis, Quadrant Selection

Given a point x, y, return the quadrant it occupies.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'''
>>> quadrant(10, 6)
1
>>> quadrant(9, -13)
4
'''


def is_pos(n: int) -> bool:
    '''Return True if `n` is greater than 0.

    >>> is_pos(1)
    True
    '''
    return n > 0


def quadrant(x: int, y: int) -> int:
    '''Return the quadrant of point `x`, `y`.

    >>> quadrant(-1, 1)
    2
    '''
    quads = ((True, True), (False, True),
             (False, False), (True, False))
    vals = is_pos(x), is_pos(y)
    return quads.index(vals) + 1


if __name__ == '__main__':
    x, y = int(input('x: ')), int(input('y: '))
    print(quadrant(x, y))

Tests

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from solution import is_pos
from solution import quadrant


def test_is_pos():
    assert is_pos(1), 'failed on positive value'
    assert not is_pos(-1), 'failed on negative value'


def test_solution_mytest():
    assert quadrant(1, 1) == 1
    assert quadrant(-1, 1) == 2
    assert quadrant(-1, -1) == 3
    assert quadrant(1, -1) == 4


def test_solution_provided():
    assert quadrant(10, 6) == 1
    assert quadrant(9, -13) == 4