Question: write a python code Create a program that will take a string input from a user to check for the max depth of nested parenthesis

write a python code

Create a program that will take a string input from a user to check for the max depth of nested parenthesis given within that string. The max depth will be returned as an integer to the user.

Conditions for the string input is to expect the user to input only a mix of integer values, parenthesis ) or ( and operators (+,-,=,/,*) symbols, no error checking is necessary on the programmers` side for these inputs.

Inputs with only parenthesis are also valid such as () () and ()(()()), these inputs would have a maximum nested depth of 1 and 2 respectively, whereas input such as )( and ((() would not be valid and have a depth of zero (as they are not properly nested and closed)

Further examples and explanation on the next slide

Sample example 1:

User input: (2 (4*4) * ((1)+9))

Output: 3 (the 1 is nested within 3 times)

Sample example 2:

User input: (9*9) + 8/3+(4*4)

Output: 1

Sample example 3:

User input: 7

Output: 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!