EOFError: EOF when reading a line, can't figure out why

EOFError: EOF when reading a line, can't figure out why

我一直在尝试制作一个 python Among Us 游戏(我猜有点像),但这个错误真的很烦人。这是我的代码:

import random
print("Python Among Us")
print()
role = ["Crewmate", "Crewmate" , "Crewmate", "Crewmate", "Crewmate", "Crewmate", "Crewmate", "Crewmate", "Crewmate", "Impostor"]
roleconfirmed = random.choice(role)
print("You are a", roleconfirmed, "!")
if roleconfirmed == ("Crewmate"):
    firstdestination = input("Where would you like to go? ")

这是控制台中的确切错误:

Python Among Us

You are a Crewmate !
Where would you like to go? Traceback (most recent call last):
  File "main.py", line 8, in <module>
    firstdestination = input("Where would you like to go? ")
EOFError: EOF when reading a line

知道为什么这个错误仍然存​​在吗?

我认为您正在使用在线 IDE,或者提供一个空输入文件以从中读取输入。

当我创建一个空文件 empty.txt 并将其作为参数传递给 运行 代码段上方时,我能够重新生成您的异常。

$ python3 main.py < empty.txt
Python Among Us

You are a Crewmate !
Where would you like to go? Traceback (most recent call last):
  File "/Users/vishvanath/Desktop/test/main.py", line 8, in <module>
    firstdestination = input("Where would you like to go? ")
EOFError: EOF when reading a line

这里,main.py包含有问题的代码段,empty.txt只是一个空文件。

所以出现错误,因为你的程序需要一个输入,但是none。