Reputation:
I have started to read the book Python for absolute beginners (3rd edition) by Michael Dawson. And one of the first challenges in the book is to run a programme the author wrote to see what it does. That is what it looks like:
# Game Over
# Demonstrates the print function
print("Game Over")
input("\n\nPress the enter key to exit.")
When I then continue to run the module the following comes up.
"> RESTART: some of my information
Game Over
Press the enter key to exit."
However, when I press enter, the programme does not quit, like he said it would do in the book. He says, the window would disappear, which it does not.
What is wrong with my computer? I have a MacBook, am however using the newest python software from the website.
If you could help me, I would be very grateful, as I am just starting out and am a little wondered what is wrong with my stuff.
Thank you
Upvotes: 0
Views: 869
Reputation: 1
I think this will work First, install keyboard package using this code
pip install keyboard
Second, Use this code
import keyboard
# Game Over
# Demonstrates the print function
print("Game Over\n\nPress the enter key to exit.")
while True:
if keyboard.is_pressed("enter"):
exit(0)
Upvotes: 0
Reputation: 2488
Answer based on comment of OP:
When I then hit enter the following comes: ">>>" with every tap on enter a new line with those three characters appears. The problem still does not close though
So, after pressing enter, you see
>>>
and if you press enter again, you see
>>>
>>>
The "program" (which is the python script) is actually closed, and you have exited. The >>>
you see is the python prompt.
To exit the python prompt, type exit()
and press enter
Upvotes: 1