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

Tell us what’s happening:

Describe your issue in detail here.

The conditionals you wrote previously are only valid for odd numbers of disks.

Add a nested if to execute when n is odd, and add one indent level to your print() and make_allowed_move() calls.

I’m stuck to this step, i have to check if the number of disk are odd but the code don’t pass.

Your code so far

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

def move(n, source, auxiliary, target):
    # display starting configuration
    print(rods, '\n')
    for i in range(number_of_moves):
        remainder = (i + 1) % 3
        if remainder == 1:
            if   (n % 2 != 0) :
                print(f'Move {i + 1} allowed between {source} and {target}')
                make_allowed_move(source, target)

### Challenge Information:
Learn Recursion by Solving the Tower of Hanoi Puzzle - Step 38

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.

Welcome to the forum @Nico99

Remove the parentheses, then remove the space before the colon.

Happy coding

This is the link to the step, please include it when you are asking for help

remove the parenthesis here, they are not needed in Python and it can confuse the tests

Thanks U all, the code passed :+1:

1 Like