我一直试图在while循环中编写一个计时器(用于输入):
import time
def main():
while True:
answer = input('calculate 12x13') #the thing here is I have to press Enter for the time.sleep to run
time.sleep(3)
if answer == '':
print('bruh')
continue
elif answer != 156:
print('good job')
break
else:
continue
main()
我也试过用定时器
threading
,但显然线程只能启动一次:
from threading import Timer
t = Timer(3, print, ['bruh'])
def main():
while True:
t.start()
answer = print('calculate 12x13')
if answer == '':
print('bruh')
elif answer != 156:
continue
else:
print('good job')
break
t.cancel()
main()
我可以运行一个类似线程中的计时器并在while循环中使用它吗?
我非常感谢你的帮助:)。