Is there any way I can stop python.exe from closing immediately after it completes? It closes faster than I can read the output.
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.")
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 (orraw_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.