Hello.
Im brand new with python and im just trying some basic programming. I was wondering if there was any way i could stop python.exe from closing immediatly after it completes. It closes faster than I can read the output. Is there any way to stop that?
Here is the program.
Width = float(input("Enter the width: "))
Height = float(input("Enter the height: "))
area = Width * Height
print("The area is", area, "square units.")
also would anyone be able to tell me how to get the program to repeat, say i needed it do do more than one question. and is there any way i can do it like "would you like to do another one? if yes then restart if no then close." something like that?
Thank you.
views:
100answers:
3It looks like you are running something in Windows by double clicking on it. This will execute the program in a new window and close the window when it terminates. No wonder you cannot read the output.
A better way to do this would be to switch to the command prompt. Navigate (cd
) to the directory where the program is located and then call it using python
. Something like this:
C:\> cd C:\my_programs\
C:\my_programs\> python area.py
Replace my_programs
with the actual location of your program and area.py
with the name of your python file.
You can't - globally, i.e. for every python program. And this is a good thing - Python is great for scripting (automating stuff), and scripts should be able to run without any user interaction at all.
However, you can always ask for input at the end of your program, effectively keeping the program alive until you press return. Use input("prompt: ")
in Python 3 (or raw_input("promt: ")
in Python 2). Or get used to running your programs from the command line (i.e. python mine.py
), the program will exit but its output remains visible.
Auxiliary answer
Manoj Govindan's answer is correct but I saw that comment:
Run it from the terminal.
And got to thinking about why this is so not obvious to windows users and realized it's because CMD.EXE is such a poor excuse for a shell that it should start with:
Windows command interpreter copyright 1999 Microsoft
Mein Gott!! Whatever you do, don't use this!!
C:>
Which leads me to point at http://stackoverflow.com/questions/913912/bash-shell-for-windows