PLease help fix my Python code, tell me also what's wrong ... def hasDuplicateParanthesis(expression): If not expression or len(expression) <= 3 : return False #empty stack of characters needed first Stack = deque () #traversing through the input expression for c in Expression : #if character is not a closing paranthesis If C != ‘)’: Stack.append(c) # if character having closed paranthesis
PLease help fix my Python code, tell me also what's wrong
...
def hasDuplicateParanthesis(expression):
If not expression or len(expression) <= 3 :
return False
#empty stack of characters needed first
Stack = deque ()
#traversing through the input expression
for c in Expression :
#if character is not a closing paranthesis
If C != ‘)’:
Stack.append(c)
# if character having closed paranthesis
else
If stack[-1] == ‘(‘ :
Return True
#pop till ‘(‘ is found
While stack[-1] != ‘(‘: stack.pop()
Stack.pop()
Return False
if —name— == ‘__main__’:
expression = ‘((X+Y))’ # let consider this a valid expression
if HasDuplicateParanthesis(expression)
Print (‘the given expression has duplicate paranthesis’)
else:
print (‘The expression does not have duplicate paranthesis’)
Step by step
Solved in 2 steps with 2 images