Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Measure WPM on free-form text
import time
def main():
print "Starting test now: begin typing free-form text."
print "Press enter to send. Send an empty message to exit."
avg = 0
tests = 0
avg = wpm_test()
tests = 1
while True:
wpm = wpm_test();
tests += 1
avg = (avg + wpm) / 2
except (KeyboardInterrupt, EmptyWPMTest):
print "\nAverage of %d WPM over %d messages" % (avg, tests)
class EmptyWPMTest(Exception):
def wpm_test():
start = time.time()
text = raw_input('\n> ')
end = time.time()
if text == '':
raise EmptyWPMTest
elapsed = end - start
wpm = calculate_wpm(text, elapsed)
return wpm
def calculate_wpm(text, seconds):
length = len(text)
print "Took", int(round(seconds)), "seconds to type", length, "characters"
words = float(length) / 5
minutes = seconds / 60
wpm = words / minutes
print "WPM:", int(round(wpm))
return wpm
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.