First time here? Check out the FAQ!

Ask Your Question
1

how to make input_box in this code?

asked 11 years ago

vigorhead gravatar image

updated 11 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 11 years ago

tmonteil gravatar image

updated 11 years ago

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),[],[])
Preview: (hide)
link

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: 11 years ago

Seen: 2,347 times

Last updated: May 20 '13