ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 30 Mar 2013 12:17:26 -0500Euclidean algorithmhttp://ask.sagemath.org/question/9760/euclidean-algorithm/Hi,
I wrote these commands in sage to have Euclidean algorithm but I only get an error.. what is the problem of this algorithm?
r=a%b
print (a,b,r)
while r != 0:
a=b; b=r
r=a%b
print (a,b,r)
by the way how can I create a file named euclid.sage and save the above command in it?Fri, 29 Mar 2013 01:23:51 -0500http://ask.sagemath.org/question/9760/euclidean-algorithm/Comment by Neda for <p>Hi,</p>
<p>I wrote these commands in sage to have Euclidean algorithm but I only get an error.. what is the problem of this algorithm?</p>
<pre><code>r=a%b
print (a,b,r)
while r != 0:
a=b; b=r
r=a%b
print (a,b,r)
</code></pre>
<p>by the way how can I create a file named euclid.sage and save the above command in it?</p>
http://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17987#post-id-17987Thank you so much! I'm using it with my notebook ..Sat, 30 Mar 2013 12:12:34 -0500http://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17987#post-id-17987Comment by vdelecroix for <p>Hi,</p>
<p>I wrote these commands in sage to have Euclidean algorithm but I only get an error.. what is the problem of this algorithm?</p>
<pre><code>r=a%b
print (a,b,r)
while r != 0:
a=b; b=r
r=a%b
print (a,b,r)
</code></pre>
<p>by the way how can I create a file named euclid.sage and save the above command in it?</p>
http://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17998#post-id-17998I edit your message as the code was unreadable...Fri, 29 Mar 2013 01:32:33 -0500http://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17998#post-id-17998Answer by vdelecroix for <p>Hi,</p>
<p>I wrote these commands in sage to have Euclidean algorithm but I only get an error.. what is the problem of this algorithm?</p>
<pre><code>r=a%b
print (a,b,r)
while r != 0:
a=b; b=r
r=a%b
print (a,b,r)
</code></pre>
<p>by the way how can I create a file named euclid.sage and save the above command in it?</p>
http://ask.sagemath.org/question/9760/euclidean-algorithm/?answer=14703#post-id-14703Hello,
First of all, your code works! The problem is that you need to specify a value to the variables a and b. The best way should be to put all that in a function as in the following
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)
Then you can do
sage: euclide(12,5)
(12, 5, 2)
(5, 2, 1)
(2, 1, 0)
To use an external file, it depends on how do you use Sage : in a console or with the notebook ?
VincentFri, 29 Mar 2013 01:37:47 -0500http://ask.sagemath.org/question/9760/euclidean-algorithm/?answer=14703#post-id-14703Comment by Neda for <p>Hello,</p>
<p>First of all, your code works! The problem is that you need to specify a value to the variables a and b. The best way should be to put all that in a function as in the following</p>
<pre><code>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)
</code></pre>
<p>Then you can do</p>
<pre><code>sage: euclide(12,5)
(12, 5, 2)
(5, 2, 1)
(2, 1, 0)
</code></pre>
<p>To use an external file, it depends on how do you use Sage : in a console or with the notebook ?</p>
<p>Vincent</p>
http://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17986#post-id-17986thanks a lot..That was so helpful ! I'm using it with my notebook :)Sat, 30 Mar 2013 12:17:26 -0500http://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17986#post-id-17986Comment by vdelecroix for <p>Hello,</p>
<p>First of all, your code works! The problem is that you need to specify a value to the variables a and b. The best way should be to put all that in a function as in the following</p>
<pre><code>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)
</code></pre>
<p>Then you can do</p>
<pre><code>sage: euclide(12,5)
(12, 5, 2)
(5, 2, 1)
(2, 1, 0)
</code></pre>
<p>To use an external file, it depends on how do you use Sage : in a console or with the notebook ?</p>
<p>Vincent</p>
http://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17991#post-id-17991@fidelbc thanks !Fri, 29 Mar 2013 03:52:03 -0500http://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17991#post-id-17991Comment by fidbc for <p>Hello,</p>
<p>First of all, your code works! The problem is that you need to specify a value to the variables a and b. The best way should be to put all that in a function as in the following</p>
<pre><code>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)
</code></pre>
<p>Then you can do</p>
<pre><code>sage: euclide(12,5)
(12, 5, 2)
(5, 2, 1)
(2, 1, 0)
</code></pre>
<p>To use an external file, it depends on how do you use Sage : in a console or with the notebook ?</p>
<p>Vincent</p>
http://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17992#post-id-17992@vdelecroix just fixed a tiny typo in your answerFri, 29 Mar 2013 03:51:07 -0500http://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17992#post-id-17992