I'm doing some very basic lessons on Python in an online class. I was given a print task to complete, but the issue is the cmd closes immediately after the script runs, so fast that I cannot read the output.
I've done some searching and this is apparently a problem newbies have been having for a while but the solution is always to open the .py file manually using cmd - that is EXACTLY what I am doing and far from being a solution, is the exact cause of the issue. It does not do this if I click-open it with Python, and it does not close if I open it in IDLE.
As instructed, I am navigating to, and opening manually from:
cmd C:\Users\Me\Desktop\Python\myfile.py
Python is set in the environment variables/been added to the PATH. To prevent confusion, it does open in cmd, waits for my input, accepts my input, and then closes. I'm clarifying because after reading many threads, the Python community always seems to be either utterly baffled by, or give degree-level explanations to, what seem to be very simple questions.
Also for anyone wondering, I'm just running:
statement = input("Enter a statement to print: ")
if statement == "Hello world":
exit()
else:
print(statement)
As the task required we print anything other than 'Hello world'. I just want the output to stay open in cmd so I can read it. The brief also stipulates I cannot run the code in IDLE, so no cheating it that way. Must be Windows cmd.
input("Hit enter to close.")before theexit()(which should be exit(0)) and after theprint(statement)to make it wait ...python myfile.py, not just typing in the filename (which opens the file, not runs it).