Use of Strings & Filters - Basic Test
The question asks to find out how many words are in a given sentence, where a word is defined as a series of letters from "a" to "z," "A" to "Z," which may also contain one or more hyphens. The sentence may conclude in a period (.), comma (,), question mark (? ), or exclamation point (!).
To solve the problem, we can split the sentence into a list of words using whitespace as a delimiter. Then, we can loop through each word in the list and remove any trailing punctuation. Finally, we can count the number of words remaining in the list.