2017-09-16 1 views
2

그래서 파이썬과 세미 코딩에 익숙하지 않으며 일반적으로 코딩하기가 힘들어졌습니다.내 텍스트 모험은 인쇄되지 않습니다. [python]

#startup 
startup = "welcome to 'da spoopy house', type 'start'" 
work = raw_input(startup) 

<here is full code> 
#functions 


#keywords 
varlook = "look" 
vargo = "go" 
varhouse = "house" 


#story 
st01 = "You are outside, its dusk. there is a house in front of you. both you and the house are surrounded by a forest" 
st02 = "You walk up to the house, you notice a small yard with flowers lining the perimeter. As you step up to the door, you notice a small note attached to the door" 


#instructions... ? 


#action 
print st01 
raw_input() 

if varlook in work: 
    print "%s" % st01 
    raw_input() 

if raw_input == ("%s to %s") % (vargo, varhouse): 
    print "%s" % st02 
    raw_input() 

내가 원하는 키워드를 입력 할 때 문제는 여기

#action 
print st01 
raw_input() 

if varlook in work: 
    print "%s" % st01 
    raw_input() 

if raw_input == ("%s to %s") % (vargo, varhouse): 
    print "%s" % st02 
    raw_input() 

입니다 단순히 다시 대기로 나를 데려 프로그램을 중지합니다. 도움을 주시면 감사하겠습니다.

+0

'raw_input을 == ("%의 % s의")의 경우'당신은 어딘가에 루프를 추가해야합니다 –

+0

. 그것 없이는 스크립트가 끝나고 종료됩니다. –

답변

1

을 발행하면 raw_input 함수를 호출 할 때 입력 문자열이 raw_input 인 변수에 할당된다는 오해가있는 것 같습니다.

사실, 이라는 함수 호출은 현재 아무 것도하지 않는 문자열을 반환합니다.이 문자열은 아무런 참조가 없기 때문에 가비지 수집되고 손실됩니다.

반환 값에 변수를 지정한 다음 다음 코드에서 변수를 사용하십시오.

데모 :

당신이`raw_input` 전화를 잊었
>>> user_input = raw_input() 
hello Emmma! 
>>> print user_input 
hello Emmma! 
관련 문제