为短语创建WPM计数器然后输出所花费的时间

时间:2015-09-17 01:37:07

标签: python wpm

所以我想创建一个简单的程序,使用time.monotonic()函数在用户键入短语之前和之后进行提示,然后每分钟给出平均值以及键入短语所需的总秒数。 / p>

短语:"快速的棕色狐狸跳过懒狗"

我是编程新手,所以我会给出下面的代码和粗略的想法,请随时纠正我。感谢所有帮助。

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

好的,所以我接受了第一张海报的建议,但是当我输入“是”后继续停止并且没有错误运行代码,所以我不确定是什么问题。

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)  

1 个答案:

答案 0 :(得分:0)

import time 
string = "The quick brown fox jumps over the lazy dog"
word_count = len(string.split())

您可以为用户准备一些介绍

while str(raw_input('Enter "yes" when you are ready')) <> 'yes':
    str(raw_input('Enter "yes" when you are ready'))

然后你启动你的计时器

t0 = time.time() #start time
inputText = str(raw_input('Enter the phrase :"%s" 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