0

I have written these lines in python and ran it. But the result appears only for a second then it closes itself. What can i do to prevent it from closing?

   print("Enter your name:")
   x = input()
   print("Hello, " + x)
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
  • Possible duplicate of [Stop Windows from closing Python](https://stackoverflow.com/questions/22436864/stop-windows-from-closing-python) – Ondrej K. Jun 12 '18 at 17:40

1 Answers1

1

There are several ways to do this.

You can run your code in console/command line/idle so that the parent process does not quit.

Or more programmatically, you can put input() at the end.

print("Enter your name:")
x = input()
print("Hello, " + x)
input() # better with a friendly note

If I recall correctly, input has platform dependent behavior handling signals/interrupts, but generally you can type <enter>, <Ctrl+C>, or <EOF> to end the program.

YiFei
  • 1,752
  • 1
  • 18
  • 33