Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python. Thank you Question 2 [25 points) Mr. Parr N. Thesis is having a problem with his parentheses. When writing, he replaces all his

image text in transcribed

Using Python. Thank you

Question 2 [25 points) Mr. Parr N. Thesis is having a problem with his parentheses. When writing, he replaces all his commas with an opening parenthesis '(', and then inserts a closing parenthesis) at the end of the sentence. For example, instead of writing 'Hello, World!' he writes 'Hello World!)'. He does this for every comma in the sentence. For example, the sentence 'Me, myself, and I' would become 'Mel myself( and I)), and the sentence 'The first five letters of the alphabet are a, b, c, and d.' would become 'The first five letters of the alphabet are al b( c( and d.))) In order to understand Mr. Thesis writings, we will write code to help translate his sentences by replacing the parentheses with commas in the appropriate positions. We will do this by writing four functions as follows. (Note that there are other ways to do this question, but you must implement each of these functions as described; we will be testing each of your functions individually. Further, like in all other questions, you can only use concepts seen in class up to and including February 5. That is, you may not use the string methods replace, index, find, rindex, rfind, partition or rpartition methods for this question.) Name: find first Parameters: A string s and character letter Return value: The first index of the character letter in the string s. (Hint: Loop over the string's indices, starting at 0.) If the character letter is not present in s, return the value None. Name: find last Parameters: A string s and character letter Return value: The last index of the character letter in the string s. (Hint: Use your code from find first but start at the last index.) If the character letter is not in s, return None. Name: get_comma-phrase Parameters: A string s containing at least one opening '/' and one closing parenthesis) Return value: The string s with the first opening parenthesis replaced by a comma, and the last closing parenthesis deleted. (Hint: Use the functions above to get the indices of the two parentheses, then use string slicing to get the parts of the string that are between the parentheses (3 parts in total), and put the parts back together with a comma inserted in the appropriate location.) Name: get_comma_string Parameters: A string s Return value: The string s with all opening parentheses replaced by commas and all closing paren- theses deleted. (Hint: The function get_comma-phrase returns a new string with the first and last parenthesis of the string deleted. If there are several sets of opening and closing parentheses in the string, then how many times should you call the function? A while loop will be useful (but you should figure out when to stop looping).)

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions