aboutsummaryrefslogtreecommitdiff
path: root/challenge-066/lubos-kolouch/python/ch-1.py
blob: e1454bead7a22b2bf8851b21b868f897ea51f43f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def divide(M: int, N: int) -> int:
    if N == 0:
        raise ValueError("Division by zero is not allowed.")

    sign = -1 if (M < 0) ^ (N < 0) else 1
    M, N = abs(M), abs(N)

    result = 0
    while M >= N:
        M -= N
        result += 1

    return sign * result


M = -5
N = -2
output = divide(M, N)
print(output)