Search code examples
pythonloopsindentationpython-idle

Python IDLE - How to type code after a loop


I'm trying to familiarize myself with IDLE by executing the following code from Automate the Boring Stuff with Python by Al Sweigart:

name = ""
while name != "Mark":
    print("What is your name?")
    name = input();
print("Thank you")

Syntax Error

For some reason though, I get a syntax error when trying to type the last print statement. I dont know how to get around the indentation / how to be able to type again OUTSIDE of the loop. I understand that only one block of code is executed at a time but I can't seem to be able to incorporate the final print statement. Does anybody know how I can get around this? Thank you very much


Solution

  • In IDLE, put an empty, unindented line after entering this line:

        name = input();
    

    Press enter again to make the extra blank line to exit that indented block and your loop should execute after that.