Question
In Python, write a words-per-minute(WPM) typing test. Weve provided the following functions: select_sentence. Returns a randomly-chosen sentence, one of the ones described above. (If you
In Python, write a words-per-minute(WPM) typing test. Weve provided the following functions:
-
select_sentence. Returns a randomly-chosen sentence, one of the ones described above. (If you call this function multiple times, it might return the same sentence more than once; thats expected and totally fine.)
-
count_word. Returns the number of words in a given sentence. It cares only about spaces to separate words.
-
count_mismatches. Returns the number of word-mismatches between two sentences. Punctuation and case matter. If one sentence is Hello World! and the other is Hello World?, that is a mismatch count of one, because Hello is typed correctly but World! is not .
Youll use these functions to put together a program that does the following:
-
Gives the user sentences to type, until they type DONE and then the test is over.
-
Counts the number of seconds from when the user begins to when the test is over.
-
Counts and prints:
-
The total number of words the user typed, and how many seconds it took them.
-
The words-per-minute that turns out to be.
-
The number of mistakes they made.
-
The adjusted words-per-minute, accounting for mistakes.
-
WPM and adjusted WPM... Suppose the user types 25 words and it takes them 30 seconds. That would be 50 words per minute. But if they made two mistakes, then we say they typed 23 words in 30 seconds, and so adjusted WPM is 46.
The number of mistakes is always subtracted from the total words typed, regardless of whether it was a misspelled word, an extra word, or a missing word.
Requirements:
-
The number of words typed and number of mistakes made should should be integers throughout the program. The words per minute and adjusted words per minute, when reported on the terminal, should be rounded to the nearest whole number.
-
The number of seconds should be rounded to the nearest 100th.
-
The test must keep going, selecting sentence after sentence after sentence until the user types DONE.
-
The user might type DONE at the very beginning and just get zeroes for everything.
Hints:
-
Python has a time module that youll probably find useful.
-
You should prompt the user to just type Enter at the beginning, and start the timer right after that.
-
You should stop the timer right after they type DONE (dont worry about any extra little bits of time it took them to type DONE).
-
(starter code listed below): sentence.py
-
**********************************************
-
import time import random PHRASES = ['Four Khoury faculty awarded Global Resilience Institute grants.', 'Tired of being manipulated by fake news?', 'One computer scientists strategies to improve data visualizations', 'Now more than ever, computer science is everywhere.', 'Prof. Manferdelli has been recognized for his work on the DSB.', 'The work of the Defense Science Board has led to effective actions.', 'Please take your dog, Cali, out for a walk; she needs exercise!', 'What a beautiful day it is on the beach, here in sunny Hawaii.', 'Dr. Quinfrey, a renowned scientist, made an invisibility machine.', 'why are all those chemicals are so hazardous to the environment?', 'The two kids collected twigs outside in the freezing cold!', 'How many times have I told you? NEVER look at your race photos.', 'Didn\'t see a moose, though. Come on, Maine.', 'Yo minneapolis is cold', 'Amazingly few discotheques provide jukeboxes!', 'Jovial Debra Frantz swims quickly with grace and expertise.', 'Six crazy kings vowed to abolish my quite pitiful jousts.', 'Rex enjoys playing with farm ducks by the quiet lazy river?', 'The five boxing wizards jumped quickly!', 'The 116 saved 49 size 64 items for 26 friends going May 3', 'Send 99 people to do 8 sets of 150 shows.', 'The new school holds 3092 students; the older one, 568 more.', 'He has seat 459 in car 985 of train 78, which is now at gate 31.', 'The 36 men won 663 prizes in 52 games and 57 in 129 others.'] def select_sentence(): ''' Function select_sentence Input: nothing Returns: a randomly-chosen sentence from the list above (string) ''' return random.choice(PHRASES) def count_words(sentence): ''' Function count_words Input: a string Returns: an int, the number of words in the given string. Uses one white space as a delimiter, nothing else. ''' words = sentence.split(' ') return len(words) def count_mismatches(phrase_one, phrase_two): ''' Function count_mismatches Input: two strings for comparison Returns: an int, the number of differences between the two strings. We count differences in each word (not each character). If the words at position i in each sentence differ at ALL, case included, that's a mismatch. If one sentence is longer than the other, each extra word it has is also a mismatch. ''' list_one = phrase_one.split(' ') list_two = phrase_two.split(' ') min_length = min(len(list_one), len(list_two)) # Count the position-by-position mismatches errors = 0 for i in range(min_length): if list_one[i] != list_two[i]: errors += 1 # Add on any mismatches if one phrase was longer errors += abs(len(list_one) - len(list_two)) return errors
- ************************************
-
Filename (your driver): typing.py
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started