2017-09-16 23 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!