From b97a18c5fa79d289d16766b13770b49ebb9ae661 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 14:52:03 +0300 Subject: [PATCH] bug fixed as per task4 --- gcd.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gcd.py b/gcd.py index 5880a5b..6722de4 100644 --- a/gcd.py +++ b/gcd.py @@ -1,13 +1,18 @@ # Wrong gcd find 5 mistakes -def gcd(a, b): - assert a <= 0 and b >= 0 +def gcd(a:int, b:int): # maybe better, could be fifth mistake + assert a >=0 and b >= 0 # first mistake while a and b: if a > b: - a = a / b + a = a % b # second mistake else: - b = b / a - return min(a, b) + b = b % a # third mistake + return max (a, b) # fourth mistake + +print(gcd(10, 0)) +print(gcd(123, 3)) +print(gcd(1000000, 64)) +print(gcd(0, 0)) # Examples