I am trying to find the greatest common factor.
I wrote a bad (intensive) algorithm that reduces the lower value by one, checks the use of% to see if it divides both the numerator and the denominator evenly if it completes. However, my while loop does not use the and operator, and as soon as the numerator divides, it stops, although this is not the correct answer.
The numbers I use are 54 and 42, the correct GCD (largest common denominator) is 6.
The answer I get is 27, which tells me when it reaches 27 and can divide 54/27 evenly, it stops. Any thoughts on how to use a and operator in a while loop in python?
Thanks!
Blakedallen
source share