#this is my very first python attempt
#Getting the name
print ""
name = raw_input("Hello, adventurer. Before we get started, why don't you tell me your name.")
while name in (""):
print "Sorry, I didn't get that."
name = raw_input("What is your name?")
if len(name) > 0:
print ""
print "%s? Good name! I hope you are ready to start your adventure!" % name
#getting right or left
print ""
print "Well %s, we are going to head north along the river, so get a move on!" % name
print ""
question = "As you head out, you quickly come across a fork in the road. One path goes right, the other goes left. Which do you chose: right or left?"
lor = raw_input(question).strip().lower()
while not "left".startswith(lor) and not "right".startswith(lor):
print "That's not a direction."
lor = raw_input(question).strip().lower()
if len(lor) > 0:
if "left".startswith(lor):
print "You went left"
elif "right".startswith(lor):
print "You went right"
else:
print "That's not a direction."
lor = raw_input(question).strip().lower()
私が間違っていることを理解していません。このコードを実行すると、question
. raw_input として。何も入力しないと、「それは方向ではありません」と正しく表示され、もう一度質問が表示されます。ただし、次に何かを入力すると、何を入力しても空白の回答が表示されます。ループが継続しないのはなぜですか?