Question: The variable sentence stores a string of words. Write code that does the following: Compute the number of words that begin and end with the
The variable sentence stores a string of words. Write code that does the following:
Compute the number of words that begin and end with the same letter including oneletter words. Store the result in the variable sameLetterCount.
Compute that number of words that contain an f or a k Store the result in the variable fkCount.
Do the following:
Split the sentence into words storing the result in a variable.
Iterate over the variable:
If the first character of the word is equal to the last letter of the word:
Apply a count pattern using the variable sameLetterCount.
If the word contains an f or a k:
Apply a count pattern using the variable fkCount.
Print the variables sameLetterCount and fkCount as shown below.
You may use the split method, the in operator to test for the existence of an f or k the or operator to join the logical expressions when testing for the existence of the letters.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
