I am puzzled with the following:
This works:
a, b = 1071, 1029
while(a%b != 0):
a, b = b, a%b
But, the following snippet returns a ZeroDivisionError error message:
a, b = 1071, 1029
while(a%b != 0):
a = b; b = a%b
while I expected both would be strictly equivalent.
Can anyone throw the light on this, please?
No. In
a, b = b, a%b
the right-hand side is evaluated into a tuple first, so a%b is calculated using the original value of a. In contrast,
a = b; b = a%b
a%b is calculated after a as been assigned the value of b, assigning a different result to b.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With