+ 2
How can we find the index of opening and closing of a parenthesis of a mathematical expression by using phython?
Your expression should contain nested paranthesis
6 Antworten
+ 3
Plz show some code related your questions
+ 1
Can any find the program..
Try to say me..
+ 1
a=["(27+34 *2+(21*6))" ]
b=[]
if open parenthesis is equal to the list
Then the index should be append to be
Other close parenthesis is equal to the a then we should pop to b
+ 1
Just start from your open parenthesis take a counter starting from 1, and walk through following characters. Whenever you see an opening parenthesis increase the counter by one, and for a closing parenthesis - decrease the counter by 1. The closing parenthesis on which the counter first becomes 0 is your matching parenthesis.
If you need a match for each open parenthesis in an expression, you can do it in one loop using a stack instead of a counter. Each time you see open parenthesis you push its index in the stack, each time you see the closing parenthesis you pop the top open parenthesis index from the stack and match it with the index of the closing parenthesis
+ 1
Can you send me the code it's for mathematical expression...
so iam unable to convert string to a int
+ 1
https://code.sololearn.com/cWFY34xv3mHn/?ref=app
This is the code i have written..
But iam unable to strore the values