Skip to content

Commit dbf78bf

Browse files
authored
Create 03 - GCD (Greatest Common Divisor).py
1 parent bea38e9 commit dbf78bf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
GCD (Greatest common divisor) - is the largest positive integer that divides the numbers without a remainder.
3+
"""
4+
5+
6+
def gcd(num_1, num_2):
7+
assert int(num_1) == num_1 and int(num_2) == num_2, 'The numbers must be integers only.'
8+
if num_1 < 0:
9+
num_1 = -1 * num_1
10+
if num_2 < 0:
11+
num_2 = -1 * num_2
12+
if num_2 == 0:
13+
return num_1
14+
else:
15+
return gcd(num_2, num_1 % num_2)
16+
17+
18+
print(gcd(48, -18))

0 commit comments

Comments
 (0)