【发布时间】:2014-06-06 20:50:21
【问题描述】:
我试图为我高中的一些数学成绩不佳的学生制作一个简单的 Python 游戏,但是由于安全问题,我们的计算机不允许运行 Python。所以我决定给他们代码并让他们在线运行,但是我去的每个站点都说代码有一个 EOFerror 和一个缩进错误。我在 Powershell 中运行了十几次代码,一切都很好。它始终专注于我的 raw_input() 声明。有人可以告诉我发生了什么,任何解决方案都将不胜感激。这只是介绍,所以没有数学,只是设置故事的东西。
def cell():
print """
"Welcome roomie!"
You wake up to find yourself in a jail cell
"You have been sleeping since the guards threw you in here.
They must have hit you pretty hard, ha ha ha."
You look around
finally your eyes focus on the source of the voice
across the room was a man
he looked as if he was nothing but skin and bone.
Then you noticed the scar... it ran down his arm
It was an open wound,
but wasn't bleeding just black.
The man followed your eyes
"Ah so you noticed, yes I am forsaken."
1) Remain quit
2) Ask about the forsaken
3) Quickly check your body for scars
4) Scream
Please choose one:"""
answer = raw_input("> ")
if answer == "1":
print '"You don\'t talk much"'
cell_name()
elif answer == "2":
print '"Not sure, all I know is if you have a scar like this"'
print '"They throw you in jail."'
cell_name()
elif answer == "3":
print '"Don\'t worry I already checked you."'
cell_name()
elif answer == "4":
print '"Shut up! Jeez pansy."'
cell_name()
else:
print "Pick one of the numbers"
cell()
def cell_name():
print "Well whats your name kid."
name = raw_input("> ")
print "Alright, nice to meet ya %r" % name
print "Well my name is Esman."
destroyed_cell()
def destroyed_cell():
print """
All of a sudden you hear a rumble...
rumble...
rumble...
silence.
"What do you suppose that wa..."
Crash!
Huge parts of the ceiling had fallen down
one had nearly crushed you
instead it had landed perfectly right next to you
the force was enough to break through the floor
you turn to check on Esman
But a huge piece of the ceiling had landed on him
1) Stare in bewilderment
2) try and help him
3) he's a dead man, leave him
Please choose one:"""
answer = raw_input("> ")
if answer == "1":
print "Hurry kid get out of here."
elif answer == "2":
print "It's no use you have to save yourself"
elif answer == "3":
print "Run!"
else:
print "Pick one of the numbers"
cell()
【问题讨论】:
-
请给我们一个网站的例子,它给你这个错误。
-
您可能需要在代码末尾添加一个额外的空行。并将 8 个空格缩进替换为 4 个空格
-
在compileonline 上试过。
EOFError: EOF when reading a line错误是由answer = raw_input("> ")引起的,但是它适用于 repl.it -
您尝试过交互式网站吗?如果没有,可能是您忘记填写“输入”框了?
-
另外,我不知道你来自哪个国家,但老师对学生使用“三色堇”之类的诽谤肯定是不合适的。
标签: python python-2.7 powershell