Question

In: Computer Science

Function Name: rhyme() Parameters: ● words - one stringcontaining multiple words Return Value: none Description:...

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

Solutions

Expert Solution

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

  • for every word in the list, we reverse it and store it in variable ' temp ' .
  • then we take its first two alphabet and store it in same variable temp.
  • now we check that if temp=='ta'      we are comparing with 'ta' because when we reversed the words in first statement of loop, then the position of last two words is also reversed , so instead of comparing with 'at' we will compare it with 'ta' .
  • if both are equal then we will print the word for which the loop was executing

Related Solutions

Write function words() that takes one input argument—a file name—and returns the list of actual words...
Write function words() that takes one input argument—a file name—and returns the list of actual words (without punctuation symbols !,.:;?) in the file. >>> words('example.txt') ['The', '3', 'lines', 'in', 'this', 'file', 'end', 'with', 'the', 'new', 'line', 'character', 'There', 'is', 'a', 'blank', 'line', 'above', 'this', 'line']
Divide by classes. Parameters and return types of each function and class member function should be...
Divide by classes. Parameters and return types of each function and class member function should be decided in advance. Write a program that computes a patient's bill for a hospital stay. The different components are: PatientAccount Class Surgery Class Pharmacy Class main program Patient Account will keep total of the patient's charges. Keep track of the number of days spent in the hospital. Group must decide on hospital's daily rate. Surgery class will have stored within it the charges for...
The minimum rate of return is a function of a company’s Multiple Choice all of the...
The minimum rate of return is a function of a company’s Multiple Choice all of the above. available bank interest rates. corporate or industry return on investment. cost of capital. Performance measures used in balanced scorecards typically fall into all of the following categories except: Multiple Choice Financial. Internal business processes. Sustainability measures. Customer. Which of the following is a characteristic of management accounting? Multiple Choice Management accounting must observe both financial accounting standards and cost accounting standards if it...
Provide a description of Prospect Theory (the nature of its value function, the probability weighting function,...
Provide a description of Prospect Theory (the nature of its value function, the probability weighting function, the loss aversion parameter, main characteristics of the theory etc.). Explain how the observed four-fold pattern of risk attitudes can be authenticated using the probability weighting function and the functional forms (positive and negative domain) of the value function.
Provide a description of Prospect Theory (the nature of its value function, the probability weighting function,...
Provide a description of Prospect Theory (the nature of its value function, the probability weighting function, the loss aversion parameter, main characteristics of the theory etc.). Explain how the observed four-fold pattern of risk attitudes can be authenticated using the probability weighting function and the functional forms (positive and negative domain) of the value function.
What is the return to the general partner assuming a one-year investment with the following parameters?...
What is the return to the general partner assuming a one-year investment with the following parameters? Investment amount: $100,000. Exit price: $115,000. Interest only debt at 50% LTV and 6% interest. NOI of $8,000. Preferred equity of $25,000 and a preferred rate of 10% with 25% of profits above a 10% IRR going to the preferred equity.
Write a function name randintlist which takes three parameters: 1.minimum 2.maximum 3.length The randintlist function should...
Write a function name randintlist which takes three parameters: 1.minimum 2.maximum 3.length The randintlist function should return a list of random int values (using random.randint) where the minimum and maximum values of those random numbers are the argument values for the first two parameters, and the length of the list(count of random integers ) is given by the argument value of the third parameter For the list of random int values returned by randintlist no two values should be equal...
Language: Python Function name : sort_by_rating Parameters : file (.csv file), category (string), order (boolean) Returns:...
Language: Python Function name : sort_by_rating Parameters : file (.csv file), category (string), order (boolean) Returns: None Description : You want to see what order the items of a particular category in your file would be in if you sorted them by rating. Given a file, a category of clothing, and an order boolean (True for ascending order, False for descending order), create a function that writes a file called “sorted_items.csv” that includes all of the items in the specified...
name 2 hormones that regulate eating and how do they function? 250 words
name 2 hormones that regulate eating and how do they function? 250 words
python practice! 1. Create a function that takes a user choice and one number as parameters...
python practice! 1. Create a function that takes a user choice and one number as parameters and returns the operation result. -Square: print the number square -Sqrt: print the square root of the number -Reverse: reverse the sign of the number (pos or neg) and print it Note: Detect invalid choices and throw an error message – Number can be anything. 2. Create a function that takes a user choice and two numbers (start and end) as parameters. For example,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT