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.Mon, 20 May 2013 08:13:29 +0200how to make input_box in this code?https://ask.sagemath.org/question/10139/how-to-make-input_box-in-this-code/I saw the tower of Hanoi from http://wiki.sagemath.org/animate
I just only want to make input box in this sage code, but it doesn't work.
http://alpha.sagenb.org/home/pub/706/ <- Here I did,
I added
@interact
def graph(n=input_box('3', label="Number")):
and spacing all the other lines
What's wrong with this codes?Mon, 20 May 2013 07:53:08 +0200https://ask.sagemath.org/question/10139/how-to-make-input_box-in-this-code/Answer by tmonteil for <p>I saw the tower of Hanoi from <a href="http://wiki.sagemath.org/animate">http://wiki.sagemath.org/animate</a>
I just only want to make input box in this sage code, but it doesn't work.</p>
<p><a href="http://alpha.sagenb.org/home/pub/706/">http://alpha.sagenb.org/home/pub/706/</a> <- Here I did,</p>
<p>I added </p>
<pre><code>@interact
def graph(n=input_box('3', label="Number")):
</code></pre>
<p>and spacing all the other lines</p>
<p>What's wrong with this codes?</p>
https://ask.sagemath.org/question/10139/how-to-make-input_box-in-this-code/?answer=14947#post-id-14947First, your variable `n` has to be a number, not a string: you should replace `'3'` by `3` in your second line:
def matrix(n=input_box(3, label="Number")):
Then, you should use this variable somewhere in your code, if you want its modification to take effect. If I assume that `n` aims to be the number of blocks, this parameter appears in the definition of the towers (at the end of the code):
towers = (range(4,0,-1),[],[])
Here, `range(4,0,-1)` is the list `[4, 3, 2, 1]` corresponding to the lengths of the blocks of the first tower. What you should do is to replace this number by your variable `n`:
towers = (range(n,0,-1),[],[])
Mon, 20 May 2013 08:13:29 +0200https://ask.sagemath.org/question/10139/how-to-make-input_box-in-this-code/?answer=14947#post-id-14947