我想学习如何使用Python 2 TDD读取标准输入,但我仍然遇到ZNEC运行时错误,并且没有解决方法帮助我通过。这是我最近的功能和测试输入():
def parens_balance(line):
parensonly = ''.join(char for char in line if char == '(' or char == ')')
parenscount = 0
for i in parensonly:
if i == '(':
parenscount +=1
elif i == ')':
parenscount +=1
if parenscount % 2 == 0:
print('{} {}'.format('Y', parensonly))
else:
print('{} {}'.format('N', parensonly))
line = input()
print(parens_balance(line))
测试用例为((1+2) * (3-4))
或(1+2)*3)+5/8)