I am trying to write a func. that finds LMC. But when i use if instead of elif, it becomes infite loop. But i didnt get why it happens. Can you explain me the logic?
def ekok(sayi,sayi1):
i = 2
b = 1
while(True):
if (sayi % i == 0) and (sayi1 % i == 0) :
b *= i
sayi //= i
sayi1 //= i
elif (sayi % i == 0) and (sayi1 % i != 0):
b *= i
sayi //= i
elif (sayi % i != 0) and (sayi1 % i == 0):
b *= i
sayi1 //= i
else :
i += 1
if (sayi == 1) and (sayi1 == 1):
break
return b
Aucun commentaire:
Enregistrer un commentaire