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

Tell us what’s happening:

I am unable to understand which if function statement needed to be changed in this can someone help me in understanding it?

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 make_allowed_move(rod1, rod2):
    pass

def move(n, source, auxiliary, target):
    # display starting configuration
    print(rods)
    for i in range(number_of_moves):
        remainder = (i + 1) % 3
        if remainder == 1:
            print(f'Move {i + 1} allowed between {source} and {target}')
            forward = False
            if not rods[target]:
                forward = True
            elif rods[source] and rods[source][-1] < rods[target][-1]:
                forward = True
            if forward:
                print(f'Moving disk {rods[source][-1]} from {source} to {target}')
                rods[target].append(rods[source].pop())
            else:
                print(f'Moving disk {rods[target][-1]} from {target} to {source}')
                rods[source].append(rods[target].pop())

            # display our progress
            print(rods)

# User Editable Region

        elif remainder == 2:
            print(f'Move {i + 1} allowed between {source} and {auxiliary}')
        elif remainder == 0:
            print(f'Move {i + 1} allowed between {auxiliary} and {target}')

# 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/136.0.0.0 Safari/537.36

Challenge Information:

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

Move the code nested inside the first if statement (except the first print() call) to your new function.

Can you say what you believe is the “first if statement”?

Note - you should show us the code you have tried

the if function which i used first time in this code is considered to be the first if statement

There is no “if function”.

Please quote the code that you think is the “first if statement”.

oh sorry my bad i meant statement only by mistakenly i told function
the first if statement is

 if remainder == 1:
print(f'Move  {i + 1} allowed between {source} and {target}')

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

No, that is not the entire “first if statement”. You should quote the entire “first if statement”.

so you mean i should take everything which falls under first if statement excluding print right?

Move the code nested inside the first if statement (except the first print() call) to your new function.

I don’t see anything about the instructions suggesting that you should ignore part of the code inside of the first if statement other than the print() call.

what about the part in the parentheses?

Yeah, edited to be more precise

i am getting confused can only one person guide me in this

Move the code nested inside the first if statement (except the first print() call) to your new function.

This sentence answers your question

ok let me try and will update you on this.

I was making sure that what Jeremy is saying is the most accurate, do not worry. my message was not directed to you

Your question is also likely answered in one of these threads previously opened on this topic:

https://forum.freecodecamp.org/search?q=Learn%20Recursion%20by%20Solving%20the%20Tower%20of%20Hanoi%20Puzzle%20-%20Step%2031%20order%3Alatest