pythonwpm

Creating a WPM counter for a phrase then output the time taken


So I want to create a simple program using the time.monotonic() function to prompt before and after the user has has typed the phrase then give the avg words per minutes along with the total seconds taken to type the phrase.

Phrase: "The quick brown fox jumps over the lazy dog"

I am new to programming so I'll give what code and rough ideas I had below please feel free to correct me. All help is appreciated.

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

Ok so I took the advise of the first poster but when I run the code after entering yes to continue it stops and there are no errors so im not to sure what is wrong.

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)  

Solution

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

    You can prepare the user with some intro

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

    Then you start your timer

    t0 = time.time() #start time
    inputText = str(raw_input('Enter the phrase :"%s" as fast as possible' % string))
    t1 = time.time() #stop time
    

    Then you can count the percentage of correctly entered words somehow

    acc = len(set(inputText.split()) & set(string.split()))
    acc = acc/word_count
    
    timeTaken = t1 - t0
    wordPM = (word_count/timeTaken)
    print wordPM, acc