Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. (a) Using Python, define a function that reverses the order of the words in a string. For instance, your function should transform the string

image text in transcribed
2. (a) Using Python, define a function that reverses the order of the words in a string. For instance, your function should transform the string "Do or do not, there is no try" to "try no is there, not do or Do". Assume that all words are space delimited and treat punctuation the same as letters. Pass the original string as a parameter to the function which will generate a new string with reversed words. The new string will be returned from the function (hint: use built-in functions of string, this program can be very short) (b) Using Python, define a function which will check if a string is a palindrome (note:a palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, e.g.. "91019", "hannah", etc.). Pass a string as a parameter to the function which will return true or false accordingly. 3. Using Python, define a class Parent and implement one property functions: prime_check() which is to check whether a number passed as parameter is prime or not (return true or false). Then define a second class Child to inherit the parent class, and implement a constructor and three property functions mean(),median(), and prime_count(). In the constructor, define a class property list with 20 elements and assign with random integers in range (0, 1000), the mean() function returns the average of the list; the median() return the median number of the list, and the prime_count() will leverage the prime_check() defined in Parent class to find the number of prime integers in the list. Hint: a prime is an integer >=2 and has only two factors: 1 and the number itself. A common way to check if an integer " is prime is: check if any of the numbers from 2, 3, ... till the largest integer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Explain international diversification and cite sources

Answered: 1 week ago