57.7k views
5 votes
The variable sentence stores a string. Write code to determine how many words in sentence start and end with the same letter, including one-letter words. Store the result in the variable same_letter_count.

User BatyrCan
by
4.9k points

1 Answer

5 votes

Answer:

sentence = "hello wow a stores good"

same_letter_count = 0

sentence_list = sentence.split()

for s in sentence_list:

if s[0] == s[-1]:

same_letter_count += 1

print(same_letter_count)

Step-by-step explanation:

*The code is in Python.

Initialize the sentence with a string

Initialize the same_letter_count as 0

Split the sentence using split method and set it to the sentence_list

Create a for loop that iterates through the sentence_list. If the first and last of the letters of a string are same, increment the same_letter_count by 1

When the loop is done, print the same_letter_count

User Jaylin
by
3.9k points