Here is a fairly straightforward solution Python to the Tower of Hanoi problem

`def move_rings(number_rings, move_from, move_to, spare_tower): """Print all steps move_to move N rings move_fromom move_tower A move_to move_tower C""" dict_rings = {0: "A", 1: "B", 2: "C"} if number_rings == 1: print("Move from", dict_rings[move_from], "to", dict_rings[move_to]) else: move_rings(number_rings-1, move_from, spare_tower, move_to) move_rings(1, move_from, move_to, spare_tower) move_rings(number_rings-1, spare_tower, move_to, move_from) if __name__ == "__main__": number_rings = 3 move_rings(number_rings, 0, 2, 1) `

I tried using a helper function (below) but this broke my code. Please can someone help me understand why?

`def helper(number_rings, move_from, move_to, spare_tower): """Helper function works out which ring to move""" if number_rings == 1: return move_from, move_to helper(number_rings - 1, move_from, spare_tower, move_to) helper(1, move_from, move_to, spare_tower) helper(number_rings - 1, spare_tower, move_to, move_from) def move_rings(number_rings): """Function prints the ring move required""" counter = 0 dict_rings = {0: "A", 1: "B", 2: "C"} move_from, move_to = helper(number_rings, 0, 2, 1) counter += 1 print("Move disc from", dict_rings[move_from], "to", dict_rings[move_to]) return counter if __name__ == "__main__": counter = move_rings(3) print(f"Solution possible in {counter} moves") `