Computer Science Path - Towers of Hanoi

Hello guys,

i face the problem, that everytime i am trying to move a disk im getting the “else” path of my last if function:

    if from_stack.get_size() == 0:
      print("\n\nInvalid Move (Error: stack is empty). Try Again")
    elif to_stack.get_size() == 0 or from_stack.peek() < to_stack.peek():
      disk = from_stack.pop()
      num_user_moves += 1
      print("\n\nInvalid Move (Error: larger disk on smaller disk). Try Again")

It seems like this one is always executing and i have no clue why … i compared it to the solution video and it should be the same.

Here is the full code:

Thanks a lot!

well what affects whether it’s executed? inspect the condition, what specific values are involved there?

Hi there, I have exactly the same problem. After looking for any mistake in the code, I watched the video and I have exactly the same code. Still not working though.

I get the feeling you treat your code like text. It’s actions. Observe the actions you’re carrying out instead of staring at the text.

1 Like