Python 输入变量在第三次尝试后运行代码
我正在创建一个测试“文本冒险”游戏,代码是基于input()文本运行的,但是当我尝试代码并键入输入变量的文本时,它直到我尝试了几次才运行 我尝试过移动input()的位置,但它也做了同样的事情Python 输入变量在第三次尝试后运行代码,python,Python,我正在创建一个测试“文本冒险”游戏,代码是基于input()文本运行的,但是当我尝试代码并键入输入变量的文本时,它直到我尝试了几次才运行 我尝试过移动input()的位置,但它也做了同样的事情 def Inputs(): while True: global Hour global Wait if input() == 'search' and Wait == False: for x in range(1): print('Yo
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
一次,并将结果存储在变量中。范围(1)中x的的意义是什么:
?t.start
不起任何作用。如果这是一个函数,你需要用括号来调用它t.start()
每次调用input()
,它都会等待新的输入。您希望请求输入一次并将其保存到变量中。每次执行if input()==“something”
时,它都将等待用户的另一行。您应该调用它一次并将结果保存在变量中,然后根据所有不同的命令测试变量。