Skip to main content
 首页 » 编程设计

python之我的文字冒险不会打印 [python]

2025年02月15日7zhenyulu

所以,我是 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() 

当我键入所需的关键字时,它只会停止程序,让我回到空闲状态。 任何帮助表示赞赏。

请您参考如下方法:

您似乎误以为调用函数 raw_input,即发出 raw_input() 会将输入字符串分配给名称为 的变量原始输入。

事实上,函数调用返回一个字符串,您目前对它什么都不做——该字符串将被垃圾收集并丢失,因为您没有对它的任何引用。

为返回值分配一个变量,然后在下面的代码中使用该变量。

演示:

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