0

Thank you for taking the time to help me out. I'm an absolute beginner and started out just today with Python and the guide I'm using is called "Python Programming for the Absolute Beginner."

What I am trying to do is simply have the system show the string "Game Over" with the text "Press enter to exit" below. Goes without saying that I also want it to close when you press exit.

Here is what I have tried.

print("Game Over")
input("Press enter to exit")

and

print("Game Over")
input("\n\nPress the enter key to exit.")

The bottom one is the example used in the book. It doesn't work. What happens is when I save it as a .py file by using IDLE and I double click it the program just opens the prompt and closes it within a splitsecond.

Jongware
  • 22,200
  • 8
  • 54
  • 100
Eddy Vinck
  • 410
  • 1
  • 4
  • 16
  • have a look to the `sys` module and its `exit` function – DevLounge Apr 20 '16 at 20:05
  • 2
    Similar answer here: [How to stop Python](http://stackoverflow.com/questions/12375173/how-to-stop-python-closing-immediately-when-executed-in-microsoft-windows) – Brett Comardelle Apr 20 '16 at 20:05
  • 1
    @Apero I think the OP's problem is that, for some reason, the `input` call is not blocking. – Akshat Mahajan Apr 20 '16 at 20:05
  • oh yeah, I suspect that IDLE kind of sends something to the program which input catches. @Veinq: can you do test = input("Press the enter key to exit.") and then print(test) ? – DevLounge Apr 20 '16 at 20:09
  • this input (py3) or raw_input (py2) issue with IDLE seems to be really common. I just googled it and found tons of discussions threads. Maybe its just an IDLE bug... Use Jupyter (new name of iPython notebook) ;-) – DevLounge Apr 20 '16 at 20:21
  • @Apero: Except OP says he/she is *double-clicking the .py file* to run it. IDLE is just being used as the editor. – John Y Apr 20 '16 at 20:24
  • then it is THIS issue: http://stackoverflow.com/questions/12375173/how-to-stop-python-closing-immediately-when-executed-in-microsoft-windows?lq=1 – DevLounge Apr 20 '16 at 20:26
  • 2
    It *should* be working when you double-click it. Are you absolutely sure you haven't entered anything else in your .py file? It's normal for the window to close right away if there is an error in your program. The most reliable option is to run the program using the Windows command prompt, as given by [this answer](http://stackoverflow.com/a/12375531). – John Y Apr 20 '16 at 20:40
  • Thanks everyone. I can't figure out how to set Python as an environment variable right now and it's getting pretty late. Will try again tomorrow. It's pretty vague to me. – Eddy Vinck Apr 20 '16 at 21:08
  • Yes, open up a command prompt in the directory containing the file and run it from there so you can see any error message. – kindall Apr 20 '16 at 21:08
  • Well.. I should've gone to bed, but I made it work! I figured out what was wrong. After trying a lot of things, I noticed that when I succesfully changed the path in environment variables I got an error saying that my system wasn't compatible because I needed a 64-bits version of Python. What I did was I uninstalled Python from my PC and installed a 64-bits version of Python only to find out that there was a box you could check to let the installer do the environment variable path for me. Thanks everyone for trying to help me! – Eddy Vinck Apr 20 '16 at 22:46

0 Answers0