Question

problem 8 & 9

Screen Shot 2019-10-01 at 4.02.54 PM.pngScreen Shot 2019-10-01 at 4.03.55 PM.pngScreen Shot 2019-10-01 at 4.04.07 PM.png

Image transcriptions

def report_progress (typed, prompt, id, send) : """Send a report of your id and progress so far to the multiplayer server . "un # BEGIN PROBLEM 8 " *** YOUR CODE HERE *<>*>* "! # END PROBLEM 8 def fastest_words_report (word_times ) : "" "Return a text description of the fastest words typed by each player . " " " fastest = fastest_words (word_times) report = ' ' for i in range (len(fastest) ) : words = ' , '. join(fastest[i]) report += 'Player {} typed these fastest: {}\n' . format(i + 1, words) return report def fastest_words (word_times, margin=le-5) : """A list of which words each player typed fastest."ull n_players = len(word_times) n_words = len(word_times[0]) - 1 assert all(len (times ) == n_words + 1 for times in word_times) assert margin > 0 # BEGIN PROBLEM 9 " ** YOUR CODE HERE *<>*>* " # END PROBLEM 9

Problem 8 (2 pt) Implement report_progress , which is called every time the user finishes typing a word. It takes a list of the words typed , a list of the words in the prompt , the user id, and a send function that is used to send a progress report to the multiplayer server. Your progress is a ratio of the words in the prompt that you have typed correctly, up to the first incorrect word, divided by the number of prompt words. For example, this example has a progress of 6.25: report_progress(["Hello", "ths", "15"], ["Hello", "this", 15", "wrong"], ...) Your report_progress function should return this number. Before that, it should end a message to the multiplayer server that is a two-element dictionary containing the keys 'id' and 'progress' . The id is passed into report_progress from the GUI. The progress is the fraction you compute. Call send on this dictionary to send it to the multiplayer server.

Problem 9 (3 pt) Implement fastest_words , which returns which words each player typed fastest. This function is called once both players have finished typing. It takes word_times and a positive margin . The word_times argument is a list of lists of word_time values, one list for each player, and within each list n+1 elements for the total elapsed time in the race after that player has finished typing each of the n words, as well as an entry at the beginning with zero elapsed time for the special word 'START' . It returns a list of lists of words, one list for each player, and within each list the words they typed the fastest. Definition: A player typed a word the fastest if the difference between their elapsed time for that word and the previous word is within margin of the smallest difference for any player. Therefore, if two players type a word within margin of each other, that word will appear in both of their lists. Be sure to use the word and e1apsed_time accessor functions for the word_time data abstraction, rather than assuming a particular data format.

def report_progress (typed, prompt, id, send) : """Send a report of your id and progress so far to the multiplayer server . "un #...
Get unstuck

372,107 students got unstuck by Course
Hero in the last week

step by step solutions

Our Expert Tutors provide step by step solutions to help you excel in your courses