如何对用户输入添加时间限制?

2024-04-25 21:50:13 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以在Python中为用户输入添加时间限制

大概是这样的:

while true:
     ans = input("please enter a text")
     timelimit = 5 seconds
     if timelimit = reach
     restart the code

另一个解决方案中给出的代码是,如果时间用完了,它仍然要求输入,而不是重新启动。是否有任何方法可以在时间用完后重新启动脚本或循环它


Tags: thetext用户trueinputif时间restart