Skip to content
Code ReadingBalanced Brackets
Break the Code

Balanced Brackets

Write a text (only ( and )) for which this function gives the wrong answer.
1def balanced(text):
2 opens = 0
3 closes = 0
4 for ch in text:
5 if ch == "(":
6 opens += 1
7 else:
8 closes += 1
9 return opens == closes