When the remainder of the move number divided by 3 is equal to 2, the movement is allowed between 'A' and 'B' (the source and the auxiliary rods).
Add an elif statement for that. Then, print the appropriate string if the condition is met.
…Which i did imo. tried to reset it a couple of times and start over but the code ist still rising an error.
addition:
my code looks strange as the system is posting it here, on the lecture the elif is underneath the if statement like here:
if remainder == 1:
print(f’Move {i + 1} allowed between {source} and {target}‘)
elif remainder == 2:
print(f’Move {i + 1} allowed between {source} and{auxiliary}’)
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 i in range(number_of_moves):
remainder = (i + 1) % 3
if remainder == 1:
print(f'Move {i + 1} allowed between {source} and {target}') elif remainder == 2:
print(f'Move {i + 1} allowed between {source} and{auxiliary}')
# 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Learn Recursion by Solving the Tower of Hanoi Puzzle - Step 20
tried it, ithink it was even seperated before and only in my copied part it was wrong because the f string was going into the next line, but made sure again that its right on the code. unfortunately its still not passing yet.
in the code it is under the if statement. i copied out a part of code in the addition at the end above to show how its looking like on the code. in the quotation of my code it came out odd smh which happens every time on this thread.
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.
like this? messed up my indentation again when copying it in :( had to fix it manually
def move(n, source, auxiliary, target):
# display starting configuration
print(rods)
for i in range(number_of_moves):
remainder=(i + 1) % 3
if (i + 1) % 3 == 1:
print(f'Move {i + 1} allowed between {source} and {target}')
elif remainder = 2:
print(f'Move {i + 1} allowed between {source} and {auxiliary}')
looks like this at first every time.
def move(n, source, auxiliary, target):
# display starting configuration
print(rods)
for i in range(number_of_moves):
remainder=(i + 1) % 3
if (i + 1) % 3 == 1:
print(f'Move {i + 1} allowed between {source} and {target}') elif remainder = 2:
print(f'Move {i + 1} allowed between {source} and {auxiliary}')
youre right, but i could swear that it was before as i had to exchange it for the remainder variable in a lecture before.
had not noticed that it changed back jokes on me but i wasnt doing that.
i changed it now again but the code still didnt 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}') elif remainder = 2:
print(f'Move {i + 1} allowed between {source} and {auxiliary}')
the indentaion there is right on the code. it always gets messed up when i copy it in
looks like this in the code on lecture (manually fixed the paste here:
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}')
elif remainder = 2:
print(f'Move {i + 1} allowed between {source} and {auxiliary}')
no its meant to compare. unfortunately its not passing. checked the elif multiple times and on code its where its meant to be. would send you a picture if i could
started it all over again and made a reset again. still not passing. thank you for your patience, but im really starting do get desperate and will take a break now. any help is still welcome since i really have no idea how to proceed from here i found out that sending pictures actually is possible so i posted also a picture this time in aaddition to the code: