저는 절대 초보자이며 Zed Shaw의 Learn Python The Hard Way를 통해 작업하고 있습니다. 오늘 프로그램을 실행할 때 어떤 이유로 나는 다른 출력을 무작위로 얻고 있습니다. 아래는 내 코드의 일부분과 일치하지 않는 입력/출력의 일부입니다. 이 코드를 여러 번 시도해 보았습니다. 때로는 코드가 제대로 작동하고 다음 함수를 호출하고 때로는 대다수를 건너 뜁니다. 여기 다른 출력을 가진 터미널에서 동일한 프로그램 실행하기
지속적으로 실행되고 있지 않은 내 코드 ... 여기def bear_room():
print "There is a bear in 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:
next = raw_input(">")
if next == "take honey":
dead("The bear looks at you and slaps your face off.")
elif next == "taunt bear" and not bear_moved:
print "The bear has moved from the door. You can go through it now."
bear_moved = True
elif next == "taunt bear" and bear_moved:
dead("The bear gets pissed off and chews your leg off.")
elif next == "open door" and bear_moved:
gold_room()
else:
print " I have no idea what that means."
가 일치하지 않는 출력 중 일부는 ... 여기 내가 프로그램을 실행하고 프롬프트에서 "왼쪽"입력을 사용입니다 .
Theresa-Beckers-MacBook-Pro:Summer 2013 Python leafgirl12$ python ex35.py
You are in a dark room.
There is a door to your right and left
Which one do you take?
>left
You stumble around the room until you starve. Good job!
나는 똑같은 일을 즉시하고이 시간은 끝났지 만 출력은 다르다.
Theresa-Beckers-MacBook-Pro:Summer 2013 Python leafgirl12$ python ex35.py
You are in a dark room.
There is a door to your right and left
Which one do you take?
>left
There is a bear in here.
The bear has a bunch of honey.
The fat bear is in front of another door.
How are you going to move the bear?
는 힙 대 스택의 문제가 될 수있는 새로운 변수를 만들 때 내가 C++로 알고 있지만, 나는 동일한 컴퓨터에 파이썬 기능에 대한 해답을 찾을 수 con't. 내가 볼 수없는 들여 쓰기 오류가있을 경우에 대비하여 코드를 다시 입력했습니다. 몇 번이나 나는 계속해서 "take honey"라고 타이핑 할 때 올바른 결과물을 얻을 수 있었지만, 이것은 절반 만 시간이 걸리고 "도발 베어"는 아직 전혀 작동하지 않습니다. 그냥 다른 사람에게 똑바로 전달됩니다. 의견이 있으십니까? 이 말이 맞는가요?
여기에 잘못된 코드를 게시했습니다. 일관되게 실행되지 않는'bear_room' 코드는 아닙니다. 그것은 일관되게 실행되지 않는'start' 코드입니다. – abarnert
"left"를 입력했을 때 우연히 앞뒤에 공백을 넣었습니까? – cmd
이 문제를 디버깅하는 가장 좋은 방법은 각'raw_input()'문 다음에 "print"와 같은 것을 추가하는 것입니다. 그래서 당신이 입력 한 것을 정확히 볼 수 있습니다. – abarnert