Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I'm writing a Sage Function for the Euclid's Algorithm. However when I run it, it doesn't compute any values. Please let me know what is wrong or anyway to help.

def euclide(a,b): r=a%b print (a,b,r) while r !=0: a=b; b=r r=a%b print (a,b,r)

sage: euclide(12,5) (12, 5, 2) (5, 2, 1) (2, 1, 0)

click to hide/show revision 2
No.2 Revision

I'm writing a Sage Function for the Euclid's Algorithm. However when I run it, it doesn't compute any values. Please let me know what is wrong or anyway to help.

 def euclide(a,b):
    r=a%b
    print (a,b,r)
    while r !=0:
        a=b; b=r
        r=a%b
        print (a,b,r)

(a,b,r)

sage: euclide(12,5) (12, 5, 2) (5, 2, 1) (2, 1, 0)

0)

How to make a function return a value

I'm writing a Sage Function for the Euclid's Algorithm. However when I run it, it doesn't compute any values. Please let me know what is wrong or anyway to help.

 def euclide(a,b):
    r=a%b
    print (a,b,r)
    while r !=0:
        a=b; b=r
        r=a%b
        print (a,b,r)

sage: euclide(12,5)
    (12, 5, 2)
    (5, 2, 1)
    (2, 1, 0)