因此,我想使用time.monotonic()函数创建一个简单的程序,在用户输入该短语之前和之后提示它,然后每分钟给出avg单词以及输入该短语所需的总秒数。
短语:“敏捷的棕色狐狸跳过懒惰的狗。”
我是编程新手,所以我会给出我下面的代码和粗略的想法,请随时纠正我。所有的帮助都是感激的。
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) 发布于 2015-09-17 01:56:42
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, acchttps://stackoverflow.com/questions/32621299
复制相似问题