Question

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

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

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

Instructions for program:

You’ll 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.

  • **************************************************

  • ***WPM.py 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 scientist’s 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

    *********my code for HW.py file *******

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()

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#It works fine now
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_input)#it should be user_input and not user_in
    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()

Add a comment
Know the answer?
Add Answer to:
My Python file will not work below and I am not sure why, please help me...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I cant get this python program to read all the unique words in a file. It...

    I cant get this python program to read all the unique words in a file. It can only read the number of the unique words in a line. import re import string from collections import Counter # opens user inputted filename ".txt" and (w+) makes new and writes def main(): textname = input("Enter the file to search: ") fh = open(textname, 'r', encoding='utf-8' ) linecount = 0 wordcount = 0 count = {} print("Sumary of the", fh) for line in...

  • In python, please help me fill in these functions given their limitations. Please use for loops....

    In python, please help me fill in these functions given their limitations. Please use for loops. def palindrome(x): """ For a given string, determine if the string is a palindrome. (The same forward and back) Input: String of any size (including empty) Return: Boolean (True if palindrome, False otherwise) Limitation: You must use a loop. Only function allowed to be used is len (if needed). Cannot use "in" besides "for var in container" """ pass def getCount(char, strng): """ Get...

  • I need python help .. I need to know if a user were to input 3...

    I need python help .. I need to know if a user were to input 3 commands to a program and run it such as specify: Usage: ./filemaker INPUTCOMMANDFILE OUTPUTFILE RECORDCOUNT (./filemaker is the program)( (INPUTCOOMANDFUILE= a text file that contains key words that need to be searched through then decided what to do ) (RECORDCOUNT= number) Given an input file that contains the following: That specifies the text, then the output, and the number of times to be repeated...

  • PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment...

    PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • 12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try...

    12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try the code and catch the errors. The other paradigm is 'Look before you leap' which means test conditions to avoid errors. This can cause race conditions. 1.Write the output of the code here: class MyError(Exception): pass def notZero(num): if num == 0: raise MyError def run(f): try: exec(f) except TypeError: print("Wrong type, Programmer error") except ValueError: print("We value only integers.") except Zero Division Error:...

  • This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of ...

    This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of the class "Burger" theOrder = Burger() # calling the main method theOrder.main() # And the class is like: class Burger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own...

  • hey dear i just need help with update my code i have the hangman program i...

    hey dear i just need help with update my code i have the hangman program i just want to draw the body of hang man when the player lose every attempt program is going to draw the body of hang man until the player lose all his/her all attempts and hangman be hanged and show in the display you can write the program in java language: this is the code bellow: import java.util.Random; import java.util.Scanner; public class Hangmann { //...

  • Can somebody help me with Java programming? please be brief and explain the process and carefully...

    Can somebody help me with Java programming? please be brief and explain the process and carefully follow the step by step instruction. Thanks Homework 12.1 - Write a program that generates five random sentences (like mad libs), prints them to a file, then reads in the sentences and prints them to the console. Start by creating four string arrays for nouns, verbs, colors, and places. They should store at least 5 of each type of word. You can have more...

  • I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt...

    I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT