Python错误:行连续字符后出现意外字符。我该怎么办?

Python错误:行连续字符后出现意外字符。我该怎么办?,python,syntax-error,Python,Syntax Error,pe=0 n=0 po=0 x=1 而x=0: y=int(输入(“输入一个数字”)) 如果y0: pe=pe+y 其他: po=po+y x=y print(“负数之和是”,n\n“正偶数之和是”,pe\n“正奇数之和是”,po)行连续字符是反斜杠\,用于分割python代码的长行(请参阅或本节) 在您的情况下,最后一行: print("The sum of negative numbers is", n \n "The sum of positive even numbers is", pe

pe=0
n=0
po=0
x=1
而x=0:
y=int(输入(“输入一个数字”))
如果y0:
pe=pe+y
其他:
po=po+y
x=y

print(“负数之和是”,n\n“正偶数之和是”,pe\n“正奇数之和是”,po)
行连续字符是反斜杠
\
,用于分割python代码的长行(请参阅或本节)

在您的情况下,最后一行:

print("The sum of negative numbers is", n \n "The sum of positive even numbers is", pe \n "The sum of positive odd numbers is", po)
字符串文本中应该有
\n
字符(或其他解决方案,但不能像
print()
函数中那样保留它们):


反斜杠不在字符串文字中,因此它表示一行的延续-该行的其余部分是无效语法。尝试类似于
打印(“…is”,n,“\n…”,…)
。查看问题的答案。
print("The sum of negative numbers is", n, "\nThe sum of positive even numbers is", pe, "\nThe sum of positive odd numbers is", po)