#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
이 표시됩니다. as raw_input. 내가 아무 것도 넣지 않으면 올바르게 "그건 방향이 아니야"라고 말하면서 두 번째 질문을 제기합니다. 그러나 다음에 내가 무엇을 넣을 때, 내가 입력 한 것과 상관없이 대답으로 비어 있습니다. 왜 계속 반복되지 않습니까?내 코드가 올바르지 않습니다.
질문을 편집하면 요청한 내용이 더 분명해질 수 있습니까? (그렇지 않으면, 모드가 당신의 질문을 닫을 것입니다.) – 2rs2ts
''left ".startswith (lor)'는 다른 길을 가야합니다 :'lor.startswith ('left')'. 그것은 아마 그 방식으로도 더 의미가 있습니다. – Blender
또한 매우 비슷한 질문을 게시하고있는 것을 보았습니다. 각 질문에 "이것은 내 첫번째 파이썬 시도입니다."라고 말합니다. 그게 확실한가요? – 2rs2ts