Search code examples
python-3.xpython-turtle

Why does my turtle window close immediately?


import turtle

ved_turtle = turtle.Turtle()
def square():
    ved_turtle.forward(100)
    ved_turtle.right(90)
    ved_turtle.forward(100)
    ved_turtle.right(90)
    ved_turtle.forward(100)
    ved_turtle.right(90)
    ved_turtle.forward(100)
    ved_turtle.right(90)

elephant_weight = 3000
ant_weight = 0.1

if elephant_weight < ant_weight:
    square()
else:
    ved_turtle.forward(0)

Why does my turtle window close immediately after opening in the community edition of Visual Studio 2019, but it does not close immediately in repl.it ?


Solution

  • Add input() at the end of the script to make it wait for the Enter key.