ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 30 Mar 2013 18:17:26 +0100Euclidean algorithmhttps://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 07:23:51 +0100https://ask.sagemath.org/question/9760/euclidean-algorithm/Comment 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>
https://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17998#post-id-17998I edit your message as the code was unreadable...Fri, 29 Mar 2013 07:32:33 +0100https://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17998#post-id-17998Comment 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>
https://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 18:12:34 +0100https://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17987#post-id-17987Answer 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>
https://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 07:37:47 +0100https://ask.sagemath.org/question/9760/euclidean-algorithm/?answer=14703#post-id-14703Comment 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>
https://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17991#post-id-17991@fidelbc thanks !Fri, 29 Mar 2013 09:52:03 +0100https://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17991#post-id-17991Comment 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>
https://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 18:17:26 +0100https://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17986#post-id-17986Comment 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>
https://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17992#post-id-17992@vdelecroix just fixed a tiny typo in your answerFri, 29 Mar 2013 09:51:07 +0100https://ask.sagemath.org/question/9760/euclidean-algorithm/?comment=17992#post-id-17992