输入变量在第三次尝试后运行代码



我正在创建一个测试"文本冒险"游戏,代码是基于input((文本运行的,但当我尝试代码并为输入变量键入文本时,它直到我尝试了几次才运行。

我试过移动input((的位置,但它也做了同样的事情。

def Inputs():
while True:
global Hour
global Wait
if input() == 'search' and Wait == False:
for x in range(1):
print('You got +',random.randint(0,5), 'food and +', random.randint(0,5), 'water')
Hour = Hour + 1
Wait = True
t.start
if input() == 'search' and Wait == True:
print('You decide to wait before looking again.')

if input() == 'search' and Wait == True:
print('You decide to wait before looking again.')

if input() == 'light' and Day == True:
print('You light a fire.')      
if input() == 'light' and Day == False:
print('You cannot light a fire, it's day.')

if input() == 'info':
print(Info())

if input() == 'craft':
print('Test Text (Finish)')

if input() == 'help':
print(Instructions)

它应该显示"你生火了">

每次调用input() == XXX时,解释器都会请求一个新的输入,因此循环在返回之前需要8个输入。

您应该调用input一次,并将结果存储在一个变量中。

相关内容

最新更新