2017-09-16 49 views
2

所以,我是新來的python和半新到一般的編碼和我只是讓我的變量打印困難的時間。我的文本冒險不會打印[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'在'的raw_input如果==( 「%s到%s」)' –

+0

你需要的地方增加一個循環。沒有它,你的腳本將達到結束並終止。 –

回答

1

您似乎有一個誤解,即對函數raw_input的調用(即發出raw_input())會將輸入字符串分配給名稱爲raw_input的變量。

事實上,函數調用返回一個字符串,目前你什麼都不做 - 字符串將被垃圾收集並丟失,因爲你沒有任何引用它。

將變量分配給返回值,然後在以下代碼中使用該變量。

演示:

>>> user_input = raw_input() 
hello Emmma! 
>>> print user_input 
hello Emmma!