What did I do wrong?

I’m doing the Towers of Hanoi -project in computer science. My code doesn’t let me play the game, even though I double checked that everything is like in the project walkthrough video. When you try to play the game, it always prints out “Invalid move, try again.”. I’ve tracked it down to the last elif/else function, but I just can’t wrap my head around the thing that’s wrong there…
Could someone please explain to me why my code isn’t working, but the exact same code works in the project walkthrough video? What should I change to make my game work as well?

Thank you in advance

I think you’re making assumptions about where are an error is coming from. You can certainly start with the section that outputs that particular error code to see if you can spot an issue but you may have to work backwards to find the actual cause.

Why not look at the contents of from_stack / to_stack etc. to see if they are what they’re supposed to be. If not keep working backwards. Does your function behave as you expect? Have you tested it outside any other loops or functions? If it’s still not there what about the stacks themselves? Are they set-up in the way you expect them to be? If you need to, check them.

3 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.