Python While Loop, the and (&) operator is not working
You should be using the keyword and
instead of the bitwise and operator &
:
while (v % d != 0) and (u % d != 0):
This is also the same:
while (v % d) and (u % d):
Note that &
and and
will give the same result in the first case, but not in the second.
Your problem though is that you want to use or
instead of and
. Also your algorithm is highly inefficient. There are better ways to calculate the GCD.