Euclid's Algorithm in Python?

Antoon Pardon apardon at
Sun Aug 14 16:41:42 CEST 2005

On 2005-08-08, Bengt Richter <bokr at> wrote:
> On 7 Aug 2005 17:31:02 -0700, "Jordan Rastrick" <jrastrick at> wrote:
>>Good point. I suppose I'd only ever seen it implemented with the if
>>test, but you're right, the plain while loop should work fine. Silly
>>def gcd(a,b):
>>     while b != 0:
>>           a, b = b, a%b
>>    return a
>>Even nicer.
> what is the convention for handling signed arguments? E.g.,

As far as I understand the convention is it doesn't make
sense to talk about a gcd if not all numbers are positive.

I would be very interested if someone knows what the gcd
of 3 and -3 should/would be.

Antoon Pardon

More information about the Python-list mailing list