Euclid's Algorithm in Python?

Jordan Rastrick jrastrick at student.usyd.edu.au
Sun Aug 7 20:31:02 EDT 2005


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
me.

def gcd(a,b):
     while b != 0:
           a, b = b, a%b
    return a

Even nicer.




More information about the Python-list mailing list