首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为短语创建WPM计数器,然后输出所需时间

为短语创建WPM计数器,然后输出所需时间
EN

Stack Overflow用户
提问于 2015-09-17 01:37:06
回答 1查看 2.2K关注 0票数 0

因此,我想使用time.monotonic()函数创建一个简单的程序,在用户输入该短语之前和之后提示它,然后每分钟给出avg单词以及输入该短语所需的总秒数。

短语:“敏捷的棕色狐狸跳过懒惰的狗。”

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

代码语言:javascript
复制
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

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

代码语言:javascript
复制
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)  
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-17 01:56:42

代码语言:javascript
复制
import time 
string = "The quick brown fox jumps over the lazy dog"
word_count = len(string.split())

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

代码语言:javascript
复制
while str(raw_input('Enter "yes" when you are ready')) <> 'yes':
    str(raw_input('Enter "yes" when you are ready'))

然后启动你的计时器

代码语言:javascript
复制
t0 = time.time() #start time
inputText = str(raw_input('Enter the phrase :"%s" as fast as possible' % string))
t1 = time.time() #stop time

然后以某种方式计算正确输入单词的百分比。

代码语言:javascript
复制
acc = len(set(inputText.split()) & set(string.split()))
acc = acc/word_count

timeTaken = t1 - t0
wordPM = (word_count/timeTaken)
print wordPM, acc
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32621299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档