Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write in Python 3, Thanks! Consider a strings that contains a pair of matching parentheses with zero or more characters between the parentheses. Examples

image text in transcribed

Please write in Python 3, Thanks!

Consider a strings that contains a pair of matching parentheses with zero or more characters between the parentheses. Examples of such strings include: 'O 'a(bcd)efg' 'The professor (and her research assistant) solved an important problem.' 'x + ((y + z) / 2) * 10 Notice that the last example string contains a pair of nested parentheses. Write a recursive function get_enclosed(s) that returns the part of the strings that is enclosed by the outermost pair of matching parentheses including the parentheses. For each of the example strings shown above your function should return the following strings: '' '(bcd)' '(and her research assistant)' ((y + z) / 2)' Your function does not need to handle strings where there are two or more pairs of matching parentheses that are not nested. Examples of such input strings that you can ignore are: '(*_^)(^_^*)' 'a(bcd)(efg)hij(klm) '(x + y) * (y + z)' Finally, if the string does not contain a matching pair of parentheses then your function should return the empty string Examples of such input strings include: ^) abcdefghi abc[def]ghi You may use the string methods startswith and endswith, but your function should not use any other string methods (such as find or index )

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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions

Question

7. Explain why retirees may be valuable as part-time employees.

Answered: 1 week ago

Question

3. Provide advice on how to help a plateaued employee.

Answered: 1 week ago