Learn Recursion by Solving the Tower of Hanoi Puzzle - Step 16

Tell us what’s happening:

Describe your issue in detail here.
I cant seem to figure out how to iterate through the number of moves and print the current move

Your code so far

NUMBER_OF_DISKS = 3
number_of_moves = 2**NUMBER_OF_DISKS - 1
rods = {
    'A': list(range(NUMBER_OF_DISKS, 0, -1)),
    'B': [],
    'C': []
}


/* User Editable Region */

def move(n, source, auxiliary, target):
    # display starting configuration
    print(rods)
    for move in range(1, number_of_moves + 1):
        print(move)

/* User Editable Region */


# initiate call from source A to target C with auxiliary B
move(NUMBER_OF_DISKS, 'A', 'B', 'C')

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn Recursion by Solving the Tower of Hanoi Puzzle - Step 16

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Hello rqzcnm9n9m,

Right now number_of_moves is exactly the amount of times you want to iterate. What you did by starting with 1 and adding +1 is very neat and will let you print 1-7. But the question doesn’t ask for it to start by 1 you can simply just use number_of_moves as the range method input to have to correct amount of iterations.

1 Like

Thank you! i think i was getting confused by all of the wording, and thinking that the range function had to be listed like range(x, y, h)!

1 Like

It can be, but it doesn’t have to be. If you just add in one input it will go that amount of times. Anyway no problem, you got this!! :blush:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.