In: Computer Science
Function Name: rhyme() Parameters: ● words - one string containing multiple words Return Value: none Description: I don’t care what all English teachers have said, I think it is a cRHYME against humanity to write a poem that doesn’t rhyme! Dr. Seuss and the Cat in the Hat would agree with that, so we are going to write a function that takes in a string of words and finds the words that rhyme with “cat” (HINT: A word that rhymes with “cat”b has to end with “at”).
Test Cases: >>>rhyme("that,rat,Holt,moose,thermostat")
Words that rhyme with cat:
that
rat
thermostat
hello,
i am providing you the definition of function in python language (since you have not mentioned any language).
code starts here:-(please mind the indentations)
def rhyme(words):
word_list=words.split(",")
for i in word_list:
temp=i[::-1]
temp=temp[:2]
if temp=='ta':
print(i)
code ends here:-
let me provide the output of test case:-
what we have done in code ???
we have simply Splitted each word in the string passed in the parameter of function ,it is stored in a list.
so now list word_list contains all the words
now we go inside an loop