Need help my code is failing to give the correct output for the last hidden case on Balanced Parentheses | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Need help my code is failing to give the correct output for the last hidden case on Balanced Parentheses

Here is my code: def balanced(expression): #your code goes here openB=0 closingB=0 result=0 for l in expression: if l=='(': openB+=1 if l==')': closingB+=1 result=openB - closingB if result==0: return True else: return False print(balanced(input()))

10th Jan 2022, 6:32 AM
Paridzaishe Foto
Paridzaishe Foto - avatar
3 Answers
+ 1
Thanks mate
10th Jan 2022, 7:20 AM
Paridzaishe Foto
Paridzaishe Foto - avatar
0
I HAVE THE EXACT SAME PROBLEM! My code is different but it solves every case except the last hidden one text = input() def balanced(text): for i in text: if text.count("(") ==text.count(")"): return True else: return False print(balanced(text))
31st Jan 2022, 3:55 PM
Wellsie
Wellsie - avatar