【问题标题】:How to skip the input statement if user not responded to it in python3?如果用户在 python3 中没有响应,如何跳过输入语句?
【发布时间】:2021-08-03 14:06:02
【问题描述】:

以下面这段代码为例

import time
for i in range(1,10):
    x=int(input("Enter any number: "))
    if x!=None:
         break
    else:
         continue

我需要的是,如果用户在 10 秒内没有响应输入提示,它应该转到下一个语句。

【问题讨论】:

    标签: python-3.x time


    【解决方案1】:

    您可以生成一个单独的线程来接收用户的输入,并在您的主程序中等待 10 秒,如果没有返回任何内容,则终止线程并将 x 设置为无。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2018-07-12
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      相关资源
      最近更新 更多