So I found this code for solving the Hanoi problem online, but tried modifying the code to save every printed line in a text file. The thing is that I only get one line saved, and I have absolutely no clue as to why. I'm pretty new to this and would appreciate it if anyone feels like answering.
def hanoi(ndisks, startPeg=1, endPeg=3):
text_file = open("hanoiresults.txt", "w")
j = 0
i = j
if ndisks:
hanoi(ndisks-1, startPeg, 6-startPeg-endPeg)
print "Move disk %d from peg %d to peg %d" % (ndisks, startPeg, endPeg)
text_file.write("Move disk %d from peg %d to peg %d" % (ndisks, startPeg, endPeg) + "\n")
j +=1
hanoi(ndisks-1, 6-startPeg-endPeg, endPeg)
text_file.close()
hanoi(ndisks=12)