括号配对检测

str=input("") t=0 for i in str: if i== "(" : t+=1 elif i== ")" : if t>0: t-=1 elif t<=0: print("配对不成功") break else: continue else: if t!= 0: print("配对不成功") else: print("配对成功")

原文地址:https://www.cnblogs.com/2640335699qqcom/p/12561343.html