【发布时间】:2014-05-14 21:59:17
【问题描述】:
我正在做Learn Python the Hard Way 一书中的练习35,我似乎无法弄清楚这个错误。这可能很愚蠢,但我似乎无法弄清楚。
错误出现在第 75、69 和 26 行,模块 start()、start bear_room() 和 bear_room next2 = raw_input("> ")
from sys import exit
def gold_room():
print "This room is full of gold. How much do you take?"
next1 = raw_input("< ")
if "0" in next1 or "1" in next1:
how_much = int(next1)
else:
dead("Man, learn to type a number.")
if how_much < 50:
print "Nice you're not greedy, you win!"
exit(0)
else:
dead("You greedy bastard!")
def bear_room():
print "There is a bear here."
print "The bear has a bunch of honey."
print "The fat bear is in front of another door."
print "How are you going to move the bear?"
bear_moved = False
while True:
next2 = raw_input("> ")
if next2 == "take honey":
dead("The bear looks at you then pimp slaps your face off.")
elif next2 == "taunt bear" and not bear_moved:
print "The bear has moved from the door. You can go through it now."
bear_moved = True
elif next2 == "taunt bear" and bear_moved:
dead("The bear gets pissed off and chews your crotch off.")
elif next2 == "open door" and bear_moved:
gold_room()
else:
print "I got no idea what that means."
def cthulu_room():
print "Here you see the great evil Cthulu."
print "He, it, whatever stares at you and you go insane."
print "Do you flee for your life of eat your head?"
next3 = raw_input("> ")
if "head" in next3:
dead("Well that was tasty!")
elif "flee" in next3:
start()
else:
cthulu_room()
def dead(why):
print why, "Good job!"
exit(0)
def start():
print "You are in a dark room."
print "There is a door to your right and left."
print "Which one do you take?"
next4 = raw_input("> ")
if next4 == "left":
bear_room()
elif next4 == "right":
cthulu_room()
else:
dead("You stumble around the room until you starve.")
start()
【问题讨论】:
-
你真的有那么多空白,还是只是你把它复制到 Stackoverflow 的方式?
-
在运行您的代码时,我没有得到
EOFError,尽管我必须修复缩进,例如bear_room。你能提供完整的追溯吗? -
我很确定 Learn Python the Hard Way 不涉及将代码转储到 Stack Overflow。
-
@FrédéricHamidi 虽然这不是世界上最好的问题 - 至少这是一个尝试过的问题...... OP 似乎愿意改进 - 让我们至少给他们一些喘息的空间?
-
@JonClements,我知道你来自哪里,但发问者甚至没有提供他们收到的实际错误,尽管有追溯。这些是这里缺少的基本反射,尽管它们不应该是。在这种情况下,我们不能向每个用户伸出援手,we have tried that before 和 it does not scale well。
标签: python-2.7 eof