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)
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)
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.