Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 #This will be the largest, most authentic program you've 2 #written so far. It will require everything you've learned 3 #and should take some

image text in transcribed

1 #This will be the largest, most authentic program you've 2 #written so far. It will require everything you've learned 3 #and should take some time to test and debug. Be patient, 4 #you can do it! 6 #write a function called average word-length that takes as 7 #input a string called my-string, and returns as output the 8 #average length of the words in the string 9# 10 #in writing this function, note the following: 11 # 12 #-You shouldaccount for consecutive spaces. A string like 13 # "H Lucy" is two words with an average length of 3.0 14# characters. 15 # -You should not assume the string starts with a letter. 16 # A string like " David" has one word with an average 17 # length of 5.0 characters. 18 # -You should not count punctuation marks toward the 19 # length of a word. A string like "Hi, Lucy" has two 20 # words with an average length of 3.0 characters: the , 21 # after "Hi" does not count as a character in the word. 22 # The only punctuation marks you need to handle are 23 # these..,!? 24 # -You may assume the only characters in the string are 25 # letters, the punctuation marks listed above, and spaces. 26 # -If my-string is not a string, you should instead return 27 # the string, "Not a string". 28 # -If there are no words in my-string, you should instead 29 # return the string, "No words". This could happen for 30 # strings like "" (an empty string) and "",!?" (a string 31 # of only punctuation marks). You may assume that any 32 # of these punctuation marks will always be followed by 33 # at least one space. 34 # 35 #Here are a few hints that might help you: 36 # 37 # -You can peak at the first character in my-string with 38 # my-string[aj. Ifmy-string is "H, Lucy", then the value 39 # of my-string[0] is "h". You don't have to do this, but 40 # you can if you want. 41 #-There are lots of ways you can do this. If you're 42 # stuck, try taking a step back and thinking about the 43 # problem from a fresh perspective 44 # -If you're still stuck, try counting words and letters 45 # separately, and worrying about average length only 46 # after both have been counted. 47 # -The word count should equal the number of letters that 48 # come immediately after a space or the start of the 49 # string. The character count should simply equal the 5 # number of characters besides spaces and punctuation 51 # marks. The average word length should be character 52 # count divided by word count

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Postgresql 16 Administration Cookbook Solve Real World Database Administration Challenges With 180+ Practical Recipes And Best Practices

Authors: Gianni Ciolli ,Boriss Mejias ,Jimmy Angelakos ,Vibhor Kumar ,Simon Riggs

1st Edition

1835460585, 978-1835460580

More Books

Students also viewed these Databases questions