n = '(())()' count = 0 for i in n: if i == '(': count += 1 else: count -= 1 if count < 0: print("False") else: if count == 0: print("True") else: print("False")
To embed this project on your website, copy the following code and paste it into your website's HTML: