+ 1

Why my Python programs don't run?

I have downloaded an example of Python program. It is a simple calculator and I have no problem to run it. but any program that I code, closes a second after It opens. what's wrong with it?

7th Feb 2018, 5:02 AM
Alex
Alex - avatar
5 Answers
+ 2
You need to create a .bat file that has your program and then a pause in it. You can look up how to do this, I know it is covered in Automate the Boring Stuff with Python which is free online.
7th Feb 2018, 11:52 AM
Mike Shaw
Mike Shaw - avatar
+ 1
It sounds like you are running this on your local machine and it opens in a command line window? If this is the case instead running it with the Python IDLE. This is probably the best way to play around with Python programs (easy way, assuming windows - right click the file, 'edit with IDLE' then in there you can run (f5 iirc))
7th Feb 2018, 7:17 AM
Dan Walker
Dan Walker - avatar
+ 1
When the program has no more code to execute it will close, so you need to ensure it ends when the user wants it to. A simple way would be to put the code in a loop so the user can keep doing inputs until they type 'exit' or something. What you probably have is a simple script that executes some lines of code then closes, when you run it as a .py file.
7th Feb 2018, 9:35 AM
Dan Walker
Dan Walker - avatar
0
that's right. but, what if I want to publish my program? then It should run without IDLE.
7th Feb 2018, 9:21 AM
Alex
Alex - avatar
0
Thank you guys.
8th Feb 2018, 2:42 AM
Alex
Alex - avatar