def div_euc1(a, b, q=0): start_a = a is_neg = 1 div_pos_uniq = False if a<0 and b<0: b = -b a = -a if b < 0: b = -b div_pos_uniq = True if a < 0: a =-a is_neg = -1 q = 0 while not a<b: a -= b q += 1 if is_neg==-1 and a != 0: q += 1 a = b - a if div_pos_uniq: if a == 0: q = - q else: a = b - a return (q*is_neg, a) liste= [(120,24),(-120,24),(120,-24),(-120,-24),(120,42),(-120,42),(120,-42),(-120,-42)] for elem in liste: print(div_euc1(elem[0],elem[1]))