Question: Write the accuracy function, which takes a typed paragraph and a reference paragraph. It returns the percentage of words in typed that exactly match the
Write the accuracy function, which takes a typed paragraph and a reference paragraph. It returns the percentage of words in typed that exactly match the corresponding words in reference. Case and punctuation must match as well. A word in this context is any sequence of characters separated from other words by whitespace, so treat "dog;" as all one word. If a typed word has no corresponding word in the reference because typed is longer than reference, then the extra words in typed are all incorrect. If typed is empty, then the accuracy is zero.
def accuracy(typed, reference): """Return the accuracy (percentage of words typed correctly) of TYPED when compared to the prefix of REFERENCE that was typed.
>>> accuracy('Cute Dog!', 'Cute Dog.') 50.0 >>> accuracy('A Cute Dog!', 'Cute Dog.') 0.0 >>> accuracy('cute Dog.', 'Cute Dog.') 50.0 >>> accuracy('Cute Dog. I say!', 'Cute Dog.') 50.0 >>> accuracy('Cute', 'Cute Dog.') 100.0 >>> accuracy('', 'Cute Dog.') 0.0 """ typed_words = split(typed) reference_words = split(reference)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
