Python Пока Loop, оператор and (&) не работает

Я пытаюсь найти самый общий фактор.

Я написал плохой (интенсивно работающий) алгоритм, который уменьшает наименьшее значение на единицу, проверяет с помощью%, чтобы видеть, делит ли он равномерно и числитель, и знаменатель, если это так, то он выходит из программы. Тем не менее, мой цикл while не использует оператор and, и поэтому, когда числитель делится, он останавливается, даже если это не правильный ответ.

Я использую числа 54 и 42, правильный GCD (наибольший общий знаменатель) - 6.

#heres a simple algorithm to find the greatest common denominator: 

iterations = 0; #used to calculate number of times while loop is executed

u = 54; v= 42; d = v-1; #u is the numerator, v is the denominator, d is the number decremented by one 

while ((v % d !=0) & (u % d != 0)): #while both numerator AND denominator cannot be evenly divided by the decremented number
 d -= 1 #decrement the number by one
 print d #print the number decremented
 iterations +=1 #add 1 to the count of iterations in while loop

print "the gcd is " +str(d) #should be 6 when the number can evenly divide both
print "the number of iterations was " +str(iterations) #display times it took algorithm to complete

Ответ, который я получаю, - 27, который говорит мне, что когда он достигает 27 и может делить 54/27, он останавливается Есть мысли о том, как использовать оператор and в цикле while в python?

Спасибо!

Ответы на вопрос(2)

Ваш ответ на вопрос