0

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)  
  • You may consider using a decorator function for this task... You will need to create a function to capture the input and decorate it with your timer decorator function... That function will also need to return the time taken. Here you can read about decorator :http://stackoverflow.com/questions/1622943/timeit-versus-timing-decorator. That way you will be able to reuse your timer decorator for other purpose it you need it. Also you should read about PEP8 : https://www.python.org/dev/peps/pep-0008/ – Richard Sep 17 '15 at 01:49
  • http://pastebin.com/QzczazfX Try this, I've tested it in `python3.4`. – hellpanderr Sep 17 '15 at 20:56

1 Answers1

0
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
hellpanderr
  • 5,581
  • 3
  • 33
  • 43
  • Hey I have been tweaking around with your answer which was very helpful! But I have had a syntax error with the: while str(raw_input('Enter "yes" when you are ready')) <> 'yes': it say the error is the <> ? Sorry still trying to grasp the concepts. –  Sep 17 '15 at 02:07
  • It's old style syntax for inequality check, in python3 you need to use `!=` instead. – hellpanderr Sep 17 '15 at 02:24