Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My Python file will not work below and I am not sure why, please help me debug! from WPM import * def main(): print( ::WORDS

My Python file will not work below and I am not sure why, please help me debug!

from WPM import *

def main(): print(" ::WORDS PER MINUTE TYPING TEST!::") print("Type this sentence:") sentence=select_sentence() print(sentence)

# Time delay of 2 seconds to let the user know when to start typing print("READY...") time.sleep(2) print("SET...") time.sleep(2) print("GO!") seconds=time.time() user_input=[] user_input = input().split()

# If sentence Ends with "DONE", it is converted into a string from a list to remove "DONE" if user_input[len(user_input)-1]=="DONE": user_input.pop() user_input=' '.join(str(x) for x in user_input) # Required calculations seconds=time.time()-seconds errors=count_mismatches(user_input,sentence) words=count_words(user_inp) seconds=round(seconds,2)

# Display of results print("TOTAL NUMBER OF WORDS TYPED: %d"%words,end='') print(" IN %d SECONDS."%seconds) wpm=(words/seconds)*60 print("WORDS PER MINUTE: %d"%round(wpm)) print("NUMBER OF MISTAKES MADE: %d"%errors) awpm=((words-errors)/seconds)*60 print("ADJUSTED WORDS PER MINUTE: %d"%round(awpm)) if __name__=='__main__': main()

***WPM Starter code file below, do not change*****

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

********************************************

Instructions for program:

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 reports:

    • 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions