Question: please help me with this hidden input... Problem Your job is to write the function prevword_ave_len(word) which takes a single argument word (a str) and

Problem Your job is to write the function prevword_ave_len(word) which takes a single argument word (a str) and returns the average length (in characters) of the word that precedes word in the text. That is, for each occurrence of word in the text, you are to determine the (single) word which precedes it, and calculate the average length of all those preceding words. If one of the occurrences of word happens to be the first word occurring in the text, the length of the preceding word for that occurrence should be counted as zero. In the instance that word doesn't occur in the text, the function should return false. Note that we define a "word" to simply be a string that is delimited by "whitespace" (i.e. punctuation following a word is included as part of the word). Additionally, the casing in the original text (and in word) should be preserved. >>> prevword_ave_len('the') 4.4 >>> prevword_ave_len('whale') False >>> prevword_ave_len('ship.') 3.0 Hint You should store the text of the paragraph as a string, and use the .split() method to make a list of the words in the text. never mind how long precisely Nm n = 0 5 = 0 1 def prevword_ave_len( word ): 2 para = "Call me Ishmael. Some years ago 3 word_list para.split() 4 5 length 6 for i in range(len (word_list)): 7 if word_list[i] == word and i != 0: 8 length += len(word_list[i-1]) 9 n = 1 10 if n == 0 : 11 return false 12 Ise: 13 avg_length = length 14 return avg_length Submissions Output 1 7 minutes ago Load #3 Not yet! Failed a test (3 tests passed). Testing the first example from the problem. Testing the second example from the problem. Testing the third example from the problem. X Testing a hidden input. LA ARA Innd
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
