[Tutor] Trouble at running

Alan Gauld alan.gauld at yahoo.co.uk
Mon Dec 21 05:33:31 EST 2020


On 21/12/2020 05:40, prashant sahu wrote:
> Sir I am a very new kind of beginner at python. I tried to execute my first
> hello world program via python 3.9.0  but the running window just opens for
> a half second and disappears,, sir what I have to modify here to keep the
> window opened for a long,,
> My program is:
> print ("hello world")

There are several ways to deal with this, the most common are:

1) Run your program from a command shell. You don't say which OS you use
but if its Linux you'll know about shells, if its MacOS I think you use
the Terminal application in the Utilities folder, and if it's Windoze use
WindowsKey-R and type in CMD.EXE.
Then when the shell window appears, at the OS prompt type

python path\to\your\python\file

This is probably the best option when developing programs since it will
show you any errors as well as the output when the code works properly.

2) Add a line like:

input("Hit enter to exit")

at the very end of your program file.
This like will print the message and then wait for the user to
type something. This is how you will normally deal with this problem
in working programs. The disadvantage is that if your code has an
error in it then you will never reach this line and the console
will still disappear. Revert to method 1 in that case.

Either that or use a tool like IDLE to develop your code since
IDLE will trap the error for you.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list