课后作业
s = input("请输入测试字符串")stack = []
for c in s:
if c == "(" or c == "[" or c == "{":
stack.append(c)
else:
if len(stack) == 0:
print("不合法")
beak
elif c == ")":
d == "("
if stack.pop(0) != d:
print("不合法")
break
elif c == "]":
d == "["
if stack.pop() != d:
print("不合法")
elif c == "}":
d == "{"
if stack.pop() != d:
print("不合法")
else:
print("合法")
代码是这样提示这个。这是为什么啊
0后边的冒号是中文的 检查是否使用中文符号
页:
[1]