Ask Your Question
1

how to make input_box in this code?

asked 2013-05-20 07:53:08 +0100

vigorhead gravatar image

updated 2013-05-20 16:49:03 +0100

tmonteil gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-05-20 08:13:29 +0100

tmonteil gravatar image

updated 2013-05-20 08:26:54 +0100

First, 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),[],[])
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-05-20 07:53:08 +0100

Seen: 2,133 times

Last updated: May 20 '13