Created
August 23, 2018 22:03
-
-
Save noskla/304191708f5fc098ecd53a31276f459c to your computer and use it in GitHub Desktop.
Made this because I was bored.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import time, random | |
sentences = [ | |
'Is there a time limit on fortune cookie predictions?', | |
'I know the voices in my head aren\'t real, but sometimes their ideas just absolutely awesome!', | |
'I got a job at a bakery because I kneaded dough.', | |
'“Work fascinates me” I can look at it for hours!', | |
'How come cats butts go up when you pet them?', | |
'Hard work never killed any body. But why take the risk?' | |
] | |
def calculate_speed(start_time, end_time, sentence): | |
words_count = len(sentence.split()) | |
char_count = len(sentence) | |
complete_time = round(end_time - start_time, 2) | |
words_per_second = round(words_count / complete_time, 1) | |
characters_per_second = round(char_count / complete_time, 1) | |
return [complete_time, words_per_second, characters_per_second] | |
if __name__ == "__main__": | |
for sentence in sentences: | |
print (f'Carefully rewrite the sentence below.\n\n{sentence}\n') | |
start_time = time.time() | |
user_input = input('>> ') | |
if user_input != sentence: | |
print('You spell it wrong. Moving forward.') | |
else: | |
end_time = time.time() | |
result = calculate_speed(start_time, end_time, sentence) | |
print(f'\nIt took you {result[0]} seconds.') | |
print(f'Your speed is {result[1]} words per second and {result[2]} characters per second.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment