Reputation: 1
I'm working on a script for making a text-based game, and no-one I ask can find the issue, so I decided to ask here. When it gets to pressing enter, it comes up with an EOF error.
The code is as follows:
import time
print("Welcome to PyGame, a text-based adventure game run entirely via Python version 3.6.8.\n")
start=str(input("Press ENTER to begin."))
if start=="":
print("Loading...")
time.sleep(3)
else:
quit()
The error, specifically, is:
Welcome to PyGame, a text-based adventure game run entirely via Python version 3.6.8.
Press ENTER to begin.
Traceback (most recent call last):
File "E:\Random\PyGame.py", line 4, in <module>
start=str(input("Press ENTER to begin."))
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
Upvotes: -1
Views: 6205
Reputation: 364
In Python 2.x input()
is not automatically evaluated as a str
type. So when Enter
is pressed it interprets the input as EOF
- End Of File when parsed, as nothing is read.
In Python 3.x the input()
function parses an empty line as a str
type.
You can try running the game in Python 3.x instead.
If you cannot use Python 3.x, try using a try, except
block to catch and ignore this exception
try:
start=str(input("Press ENTER to begin."))
except Exception as e:
start = ""
Upvotes: -1