11.7k views
2 votes
Please use Python 3 to solve the following problem. Please also show all outputs and share code.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.Hard-coded answers will receive no credit.sentence = "students flock to the arb for a variety of outdoor activities such as jogging and picnicking"

User Pedrog
by
5.2k points

1 Answer

2 votes

Answer:

The code is given in Python below with its output.

Step-by-step explanation:

"""

User is asked to enter the input in sentence

"""

sentence=input("Enter the sentence :")

"""

sentence is converted to list named words

"""

words=sentence.split()

same_letter_count=0

"""

In for loop we access each word

and check character at index 0 and at last index

is same or not.

"""

for word in words:

if word[0] == word[len(word)-1]:

same_letter_count+=1

print("The same letter count is",same_letter_count)

OUTPUT::

TEST CASE 1::

Enter the sentence :students flock to the arb for a variety ofoutdoor activities such as jogging and picknicking

The same letter count is 2

TEST CASE 2::

Enter the sentence :i am a bit madam

The same letter count is 3

User Adianez
by
5.2k points