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.Sun, 30 Jun 2013 03:54:01 +0200Perform arithmetic on previous answer/result, without copying/re-entering it?https://ask.sagemath.org/question/10295/perform-arithmetic-on-previous-answerresult-without-copyingre-entering-it/I enter the following in sage:
<code>361-4*-216 #sage comment: I would like sqrt this without copying & pasting<code>
I'd like to then obtain the sqrt of that answer after its been generated.
On the Ti-83 plus, the device was able to generate 'Ans' after I pressed an arithmetic symbol such as division.Sat, 29 Jun 2013 19:32:56 +0200https://ask.sagemath.org/question/10295/perform-arithmetic-on-previous-answerresult-without-copyingre-entering-it/Answer by dazedANDconfused for <p>I enter the following in sage:</p>
<p><code>361-4*-216 #sage comment: I would like sqrt this without copying & pasting<code></code></code></p><code><code>
<p>I'd like to then obtain the sqrt of that answer after its been generated.</p>
<p>On the Ti-83 plus, the device was able to generate 'Ans' after I pressed an arithmetic symbol such as division.</p>
</code></code> https://ask.sagemath.org/question/10295/perform-arithmetic-on-previous-answerresult-without-copyingre-entering-it/?answer=15160#post-id-15160If you're in a notebook environment and type 361-4*-216 into a cell and get the answer then in the cell underneath you would refer to the previous calculation using the _ symbol. So typing sqrt(_) will give you the square root of the calculation in the previous cell. I find it's easiest to assign calculations to variables, eg a=361-4*-216, after which you can use the variable in other calculation easily.
![image description](/upfiles/13725567524007407.png)Sat, 29 Jun 2013 20:13:38 +0200https://ask.sagemath.org/question/10295/perform-arithmetic-on-previous-answerresult-without-copyingre-entering-it/?answer=15160#post-id-15160Comment by Eviatar Bach for <p>If you're in a notebook environment and type 361-4<em>-216 into a cell and get the answer then in the cell underneath you would refer to the previous calculation using the _ symbol. So typing sqrt(_) will give you the square root of the calculation in the previous cell. I find it's easiest to assign calculations to variables, eg a=361-4</em>-216, after which you can use the variable in other calculation easily.
<img alt="image description" src="/upfiles/13725567524007407.png"/></p>
https://ask.sagemath.org/question/10295/perform-arithmetic-on-previous-answerresult-without-copyingre-entering-it/?comment=17419#post-id-17419This also works in the command-line version; the underscore holds the result of the last returned computation.Sun, 30 Jun 2013 03:54:01 +0200https://ask.sagemath.org/question/10295/perform-arithmetic-on-previous-answerresult-without-copyingre-entering-it/?comment=17419#post-id-17419Comment by bxdin for <p>If you're in a notebook environment and type 361-4<em>-216 into a cell and get the answer then in the cell underneath you would refer to the previous calculation using the _ symbol. So typing sqrt(_) will give you the square root of the calculation in the previous cell. I find it's easiest to assign calculations to variables, eg a=361-4</em>-216, after which you can use the variable in other calculation easily.
<img alt="image description" src="/upfiles/13725567524007407.png"/></p>
https://ask.sagemath.org/question/10295/perform-arithmetic-on-previous-answerresult-without-copyingre-entering-it/?comment=17421#post-id-17421The underscore symbol?
I tried that and got a TypeError message:
Traceback (click to the left of this block for traceback)
...
TypeErrorSat, 29 Jun 2013 21:24:51 +0200https://ask.sagemath.org/question/10295/perform-arithmetic-on-previous-answerresult-without-copyingre-entering-it/?comment=17421#post-id-17421Comment by dazedANDconfused for <p>If you're in a notebook environment and type 361-4<em>-216 into a cell and get the answer then in the cell underneath you would refer to the previous calculation using the _ symbol. So typing sqrt(_) will give you the square root of the calculation in the previous cell. I find it's easiest to assign calculations to variables, eg a=361-4</em>-216, after which you can use the variable in other calculation easily.
<img alt="image description" src="/upfiles/13725567524007407.png"/></p>
https://ask.sagemath.org/question/10295/perform-arithmetic-on-previous-answerresult-without-copyingre-entering-it/?comment=17420#post-id-17420Yes. I attached a picture to my answer.Sat, 29 Jun 2013 22:47:08 +0200https://ask.sagemath.org/question/10295/perform-arithmetic-on-previous-answerresult-without-copyingre-entering-it/?comment=17420#post-id-17420