Please help me to use python write this question thanks Get
Please help me to use python write this question, thanks.
Get a string of parenthesis and other letters. Return True if the number of opening parenthesis is the same as the number of closing parenthesis (the parenthesis don\'t have to \"match\".)Solution
# -*- coding: utf-8 -*-
def parenthesesChecker(s): //defining function
\"\"\" Return True if the parentheses in string s match, otherwise False. \"\"\"
i = 0
for str in s: //checking the character in the string
if str == \')\': //if the string is opening bracket
i -= 1 //decrease the index value
if i < 0:
return False
elif str == \'(\':
i += 1
return i == 0
print(parenthesesChecker(\'((()))\')) //calling function
print(parenthesesChecker(\'(()\'))
print(parenthesesChecker(\'(5+6)(7+8)/(4+3))\'))
****OUTPUT***
True
False
False
****OUTPUT***
Note:Please remove the commented lines while running the program.
Please let me know in case of any doubt
