Python-如何获得time.sleep以运行正在询问的问题?

问题描述

因此,我正在尝试使此time.sleep超时,以解决用户输入不及时的问题。刚开始,我尝试使用if语句,例如if e == None&time.sleep()== None,但这不是它的工作原理,因此我了解了线程以及.start和.join函数。但是它们仍然在随后而不是同时运行。

import random
from threading import *
import time

def upcardeighteen():
 z = random.randint(5,8000)
 y = z * 2
 for i in range(100000):
   if y > 80000:
     continue
   else:
     print("%r * 2"%str(z))
     e = int(input("What is the answer?"))
     if e == y:
       print("correct")
       break
  
       
     elif e != y:
       print("wrong")
       print(y)
       break

def upcardnineeleven():
 z = random.randint(5,8000)
 y = z * 5
 for i in range(100000):
   if y > 80000:
     continue
   else:
     print("%r * 5"%str(z))
     e = int(input("What is the answer?"))
     if e == y:
       print("correct")
       break
  
       
     elif e != y:
       print("wrong")
       print(y)
       break
    

def upcardblackjack():
 z = random.randint(5,8000)
 y = z * 10
 for i in range(100000):
   if y > 80000:
     continue
   else:
     print("%r * 10"%str(z))
     e = int(input("What is the answer?"))
     if e == y:
       print("correct")
       break
  
       
     elif e != y:
       print("wrong")
       print(y)
       break

def upcardajspades():
 z = random.randint(5,8000)
 y = z * 60
 for i in range(100000):
   if y > 80000:
     continue
   else:
     print("%r * 60"%str(z))
     e = int(input("What is the answer?"))
     if e == y:
       print("correct")
       break
  
       
     elif e != y:
       print("wrong")
       print(y)
       break

def busterfour():
 z = random.randint(5,8000)
 y = z * 3
 for i in range(100000):
   if y > 80000:
     continue
   else:
     print("%r * 3"%str(z))
     e = int(input("What is the answer?"))
     if e == y:
       print("correct")
       break
  
       
     elif e != y:
       print("wrong")
       print(y)
       break

def busterfive():
 z = random.randint(5,8000)
 y = z * 5
 for i in range(100000):
   if y > 80000:
     continue
   else:
     print("%r * 5"%str(z))
     e = int(input("What is the answer?"))
     if e == y:
       print("correct")
       break
  
       
     elif e != y:
       print("wrong")
       print(y)
       break

def bustersix():
 z = random.randint(5,8000)
 y = z * 25
 for i in range(100000):
   if y > 80000:
     continue
   else:
     print("%r * 25"%str(z))
     e = int(input("What is the answer?"))
     if e == y:
       print("correct")
       break
  
       
     elif e != y:
       print("wrong")
       print(y)
       break

def busterseven():
 z = random.randint(5,8000)
 y = z * 100
 for i in range(100000):
   if y > 80000:
     continue
   else:
     print("%r * 100"%str(z))
     e = int(input("What is the answer?"))
     if e == y:
       print("correct")
       break
  
       
     elif e != y:
       print("wrong")
       print(y)
       break

def bustereightplus():
 z = random.randint(5,8000)
 y = z * 200
 for i in range(100000):
   if y > 80000:
     continue
   else:
     print("%r * 200"%str(z))
     e = int(input("What is the answer?"))
     if e == y:
       print("correct")
       break
  
       
     elif e != y:
       print("wrong")
       print(y)
       break

def basenaturalbj():
 z = random.randint(5,8000)
 y = z * 1.5
 for i in range(100000):
   if y > 80000:
     continue
   else:
     print("%r * 1.5"%str(z))
     e = int(input("What is the answer?"))
     if e == y:
       print("correct")
       break
  
       
     elif e != y:
       print("wrong")
       print(y)
       break

#random.shuffle([upcardeighteen,upcardnineeleven,upcardblackjack,upcardajspades,basenaturalbj,busterfour,busterfive,bustersix,busterseven,bustereightplus])

class runtyme(Thread):
  def running():
    print("Do you want another problem?")
    keeper = input("y or n? ")
    for i in range(100000):
      if keeper != 'y':
        break
      else:
        k = random.randint(1,10)
        if k == 1:
          upcardeighteen()
          continue
        elif k == 2:
          upcardnineeleven()
          continue
        elif k == 3:
          upcardblackjack()
          continue
        elif k == 4:
          upcardajspades()
          continue
        elif k == 5:
          basenaturalbj()
          continue
        elif k == 6:
          busterfour()
          continue
        elif k == 7:
          busterfive()
          continue
        elif k == 8:
          bustersix()
          continue
        elif k == 9:
          busterseven()
          continue
        elif k == 10:
          bustereightplus
          continue

class bigtyme(Thread):
  def timer():
    time.sleep(5)
    print("time's up")

#x = threading.Thread(target=thread_function,args=(1,),daemon=True)
#Thread.start_new_thread(running,("Thread-1",2,) )
#Thread.start_new_thread(timer,("Thread-2",4,) )

def runninmane():
  t1 = bigtyme.timer()
  t2 = runtyme.running()
  t2.start()
  t1.start()
  t1.join()
  t2.join()

runninmane()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...