Ask Your Question

how to make input_box in this code?

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

vigorhead gravatar image

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

tmonteil gravatar image

I saw the tower of Hanoi from I just only want to make input box in this sage code, but it doesn't work. <- Here I did,

I added

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

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

tmonteil gravatar image

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

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


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

Seen: 1,891 times

Last updated: May 20 '13