Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 定时While循环_Loops_Python 3.x_Input_Timer_While Loop - Fatal编程技术网

Loops 定时While循环

Loops 定时While循环,loops,python-3.x,input,timer,while-loop,Loops,Python 3.x,Input,Timer,While Loop,我是Python新手,我需要一些帮助来完成我正在尝试做的事情。我正在运行Python 3。我需要能够为我设置为20秒的计时器输入,并在每次输入后重新出现“使用…输入单词”行,然后在计时器启动时结束循环,不再接受输入。抱歉,如果我的编码标准很糟糕,我是Python新手 Arbitrary = False while time.time() - start < timeOut: Arbitrary = True if Arbitrary == True :

我是Python新手,我需要一些帮助来完成我正在尝试做的事情。我正在运行Python 3。我需要能够为我设置为20秒的计时器输入,并在每次输入后重新出现“使用…输入单词”行,然后在计时器启动时结束循环,不再接受输入。抱歉,如果我的编码标准很糟糕,我是Python新手

Arbitrary = False    
while time.time() - start < timeOut:
    Arbitrary = True    
    if Arbitrary == True :
        Giveword = input("%s %10s%s" %("Enter a word using ", toPrint,": "))
break
print("Time's Up!")
arbitral=False
while time.time()-开始<超时:
任意=真
如果任意==真:
Giveword=输入(“%s%10s%s%”)(“使用“、toPrint、”:”)输入单词)
打破
打印(“时间到了!”)

下面是一个更简单的代码,它给出了列表中的单词

words = []
while time.time() - start < timeOut:
    Giveword = input("%s %10s%s" %("Enter a word using ", toPrint,": "))
    words.append(Giveword)
print("Time's Up!")
print("Here are your words:", words)
words=[]
while time.time()-开始<超时:
Giveword=输入(“%s%10s%s%”)(“使用“、toPrint、”:”)输入单词)
words.append(Giveword)
打印(“时间到了!”)
打印(“这是您的文字:”,文字)

这是你需要的吗?如果没有,请澄清问题

乍一看,没有尝试过,代码看起来不错。(除了完全无意义的
如果任意==True:
检查始终为True)它不工作吗?如果是,问题是什么?是否要将单词保存在列表中?或者,您想在时间结束时中止当前输入吗?实际上,我希望能够同时执行这两项操作,在列表中保存条目,以及在时间结束后停止启用输入…我可能忽略了将输入放入列表的部分,我的坏
列表()
应该是
列表()
,或者更好的是
[]
。此外,该格式字符串可以简化为
“使用%10s输入单词:”%toPrint
请删掉称呼语。这正是我需要的,非常有用!!非常感谢大家