[英]timer not working in python 2.7
i am using Python 2.7 for some coding for fun at home, and i can't figure out why this code doesn't work. 我在家里使用Python 2.7编写一些有趣的代码,但我不知道为什么这些代码无法正常工作。 I try it and it works fine, but says that i did in in -0.000938375024452 seconds... any help very much appreciated
我尝试了一下,效果很好,但是说我在-0.000938375024452秒内完成了工作……任何帮助我都非常感谢
import timeit
import time
alphabet = "abcdefghijklmnopqrstuvwxyz"
again = "yes"
print "Hi."
time.sleep(1)
print "How quick can you type the alphabet?"
time.sleep(1)
print "Well you're about to find out..."
while "YES" in again.upper():
time.sleep(2)
begin = raw_input("When you are ready, press enter and type the alphabet.")
start = timeit.timeit()
attempt1 = raw_input("")
end = timeit.timeit()
time1 = end - start
if attempt1.upper() == alphabet.upper():
print "Ok. You did it in..."
time.sleep(1)
print time1,"seconds!"
time.sleep(1)
again = raw_input("Would you like another go?")
else:
print "Sorry, but that was incorrect."
time.sleep(1)
print "Try again."
again = "yes"
timeit.timeit()
does not return you a timestamp. timeit.timeit()
不会返回时间戳。 It runs pass
1000000 times and returns you the duration of it. 它运行
pass
100万倍,并返回它的持续时间。
Use time.time()
instead. 请改用
time.time()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.