本帖最后由 wkdxz 于 2022-10-27 15:41 编辑
有个小问题,如果一直不答题的话,超时不会退出
[Python] 纯文本查看 复制代码 from time import perf_counter
from random import randint
from os import system
def chuti():
x = randint(10, 50)
y = randint(10, 50)
return f'{x} + {y} = ', x + y
system('title 一分钟计时做题')
dui = 0
cuo = 0
n = 1
start = perf_counter() + 60
while start > perf_counter() and n <= 10:
system('cls')
print(f'第{n}题 - 当前答对 {dui} ,答错 {cuo}\n----------------------------\n\n')
ti, res = chuti()
#print(ti, res)
q = input(f'请回答:{ti}')
if int(q) == res:
print('答对了')
dui += 1
else:
print('答错了')
cuo += 1
n += 1
system('cls')
print('答题结束!\n\n')
print(f'答题结果:当前答对 {dui} ,答错 {cuo}')
|