CZH206 发表于 2020-3-24 11:54:11

刚学不到一个月。如何让给Python加入计时模块?求求了。

如何给这段代码加入计时的模块(Python)
import time
print('-----------口算检测----------')
time.sleep(1)
print("注意:本次检测共十道0-100的口算题。累计答对六道为及格。每次输入完数值后请按'enter'以确定答案。")
time.sleep(1)
print('预祝您取的好成绩!')
time.sleep(1)
x = int(input('输入"1"以确定开始检测:'))
while x == 1:
    a = int(input('请输入您想口算的算法(加法1减法2乘法3)'))
    import random
    times = 1
    right = 0
    z = 0
    h = 0

    if a == 1 or a == 2 or a == 3:      
      time.sleep(1)
      input('请按"enter"开始检测:')
      time.sleep(1)
      
      while times < 11:            
            b = random.randint(1,100)
            c = random.randint(1,100)
            
            if a == 1:               
                print(b)
                print('+')
                print(c)
                d = int(input('请输入您的答案:'))
                time.sleep(0.5)
                print('正确答案是:')
                time.sleep(0.1)
                print(b + c)
                e = b + c
               
                if d == e:                  
                  time.sleep(0.5)
                  print('恭喜您回答正确!')
                  right += 1
                  
                else:
                  print('回答错误!')
                times += 1
               
            if a == 2:               
                if b < c:                  
                  h = c
                  z = b
                  
                else:                  
                  z = c
                  h = b
                  
                print(h)
                print('-')
                print(z)
                d = int(input('请输入您的答案:'))
                time.sleep(0.5)
                print('正确答案是:')
                time.sleep(0.1)
                print(h - z)
                e = h - z
               
                if d == e:                  
                  time.sleep(0.5)
                  print('恭喜您回答正确!')
                  right += 1
                  
                else:                  
                  print('回答错误!')
                times += 1
               
            if a == 3:
                w = random.randint(1,10)
                q = random.randint(1,100)
                              
                print(w)
                print('*')
                print(q)
                d = int(input('请输入您的答案:'))
                time.sleep(0.5)
                print('正确答案是:')
                time.sleep(0.1)
                print(w * q)
                e = w * q
               
                if d == e:                  
                  time.sleep(0.5)
                  print('恭喜您回答正确!')
                  right += 1
                  
                else:                  
                  print('回答错误!')
                times += 1
               
      else:            
            print('本次测试结束!')
            time.sleep(0.5)
            print('您答对的题数是:')
            time.sleep(0.5)
            print(right)
            
            if 3 < right < 6:               
                time.sleep(0.5)
                print('差一点点就及格啦,继续努力吧!')
               
            elif right < 4:               
                time.sleep(0.5)
                print('这次你没能及格,还需努力呦!')
               
            elif 6 <right < 10:               
                time.sleep(0.5)
                print('恭喜你及格啦,继续努力吧!')
               
            elif right > 9:               
                time.sleep(0.5)
                print('恭喜你,满分哦!')
            time.sleep(1)
            print('拜拜~~~')
      x = int(input('输入"1"再次检测:'))            
    else:      
      print('输入错误!请重启程序!')
   
else:
    print('再见!')

六小鸭 发表于 2020-3-24 11:56:30

https://blog.csdn.net/weixin_33851177/article/details/89718719

CZH206 发表于 2020-3-24 12:04:18

六小鸭 发表于 2020-3-24 11:56
https://blog.csdn.net/weixin_33851177/article/details/89718719

不是这个,

zltzlt 发表于 2020-3-24 12:59:18

基本不可能实现,因为要用到多线程,极其麻烦

CZH206 发表于 2020-3-24 13:29:34

zltzlt 发表于 2020-3-24 12:59
基本不可能实现,因为要用到多线程,极其麻烦

好吧
页: [1]
查看完整版本: 刚学不到一个月。如何让给Python加入计时模块?求求了。