限时输入? [英] Time-Limited Input?

查看:18
本文介绍了限时输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够做的是使用输入向用户提问.例如:

What I would like to be able to do is ask a user a question using input. For example:

print('some scenario')
prompt = input("You have 10 seconds to choose the correct answer...
")

然后如果时间过去了,打印出类似的东西

and then if the time elapses print something like

print('Sorry, times up.')

任何为我指明正确方向的帮助将不胜感激.

Any help pointing me in the right direction would be greatly appreciated.

推荐答案

有趣的问题,这似乎有效:

Interesting problem, this seems to work:

import time
from threading import Thread

answer = None

def check():
    time.sleep(2)
    if answer != None:
        return
    print("Too Slow")

Thread(target = check).start()

answer = input("Input something: ")

这篇关于限时输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆