Advertisement
George_Ivanov05

0.4 Balanced brackets

May 29th, 2021
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. n = int(input())
  2. opening_brackets_count = 0
  3. closing_brackets_count = 0
  4. is_balanced = False
  5.  
  6. for i in range(0, n):
  7.     text = input()
  8.     if text == "(":
  9.         opening_brackets_count += 1
  10.     elif text == ")":
  11.         closing_brackets_count += 1
  12. if closing_brackets_count == opening_brackets_count:
  13.     is_balanced = True
  14.     print(f"BALANCED")
  15. else:
  16.     print(f"UNBALANCED")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement