How can I stop the 'input()' function after a certain amount of time?

后端 未结 2 828
一个人的身影
一个人的身影 2021-01-28 12:13

I\'m trying to figure out how to make python stop accepting input after a certain amount of time.

What I\'ve got so far works, but won\'t stop the program until the user

2条回答
  •  梦如初夏
    2021-01-28 12:51

    just use time.sleep() The sleep method causes a python program to freeze for certain amount of time (in milliseconds). So, if you want to stop input() for a certain amount of time then you can do it this way,

    from time import sleep
    sleep(1000) #stops the program for 1 seconds
    s = input()
    

    sauce

提交回复
热议问题