我想在我的代码的函数内运行一个计时器。我需要在用户开始键入之前稍微启动计时器,然后在用户正确输入字母时停止计时器。 这里是我的代码:如何在python中的另一个def函数中运行一个def函数?
import time
timec = 0
timer = False
print("Type the alphabet as fast as possible.\nYou MUST be accurate!\nYou will be timed")
timer = True
attempt = input("The timer has started!\nType here: ")
while timer == True:
time.sleep(1)
timec = timec +1
if attempt == "abcdefghijklmnopqrstuvwxyz":
timer = False
print("you completed the alphabet correctly in", timec,"seconds!")
else:
print("There was a mistake! \nTry again: ")
的问题是,它不会让我进入字母表。在此代码(我没有)的尝试中,我已能够输入字母表,但计时器不起作用。任何帮助表示赞赏
您需要实现多线程。 –
那是什么? def功能? – Student
记录时间可能会更简单,提示用户开始输入,然后当他们按回车键时,“输入”调用返回,记录结束时间。所花费的时间将是结束减去开始。 – FamousJameous