所以我想创建一个简单的程序,使用 time.monotonic() 函数在用户输入短语之前和之后进行提示,然后给出每分钟的平均单词以及输入短语所花费的总秒数。
短语:“敏捷的棕色狐狸跳过懒惰的狗”
我是编程新手,所以我会在下面给出我的代码和粗略的想法,请随时纠正我。感谢所有帮助。
import time
inputText = str(input('Enter the phrase :"The quick brown fox jumps over the lazy dog" as fast as possible')
t0 = time.time() #start time
t1 = time.time() #stop time
timeTaken = t1 - t0
wordPM = (9/timeTaken)
#print time taken in seconds and avg WPM
好的,所以我接受了第一张海报的建议,但是当我在输入 yes 后运行代码以继续时,它会停止并且没有错误,所以我不确定出了什么问题。
import time
string = "The quick brown fox jumps over the lazy dog"
word_count = len(string.split())
while str(input('Enter "yes" when you are ready')) != 'yes':
str(input('Enter "yes" when you are ready'))
t0 = time.time() #start time
inputText = str(input('Enter the phrase :"The quick brown fox jumps over the lazy dog" as fast as possible' % string))
t1 = time.time() #stop time
acc = len(set(inputText.split()) & set(string.split()))
acc = acc/word_count
timeTaken = t1 - t0
wordPM = (word_count/timeTaken)
print (wordPM, acc)