-1

pe = 0
n = 0
po = 0
x = 1
while x!=0:
    y = int(input("Enter a number: "))
    if y<0:
        n = n+y
    elif y%2==0 and y>0:
        pe = pe+y
    else:
        po = po+y
    x = y
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)

I get the error mentioned in the title when I run this program. What am I doing wrong?

PTH
  • 51
  • 6
  • 1
    The backslash isn't inside a string literal, so it indicates a line continuation - the rest of that line is invalid syntax. Try something like `print("... is", n, "\nThe ...", ...)`. – jonrsharpe Dec 20 '18 at 15:02
  • look at the answer to [this](https://stackoverflow.com/questions/53817694/flask-werkzeug-formparser-py-exception/53818077#53818077) question. – Flob Dec 20 '18 at 15:08

1 Answers1

0

A line continuation character is the backslash \ and it is used to split long lines of python code (see this question or this section of PEP-8).

In your case, the last line:

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)

should have the \n chars inside the string literals (or some other solution, but you cannot leave them like that inside the print() function):

print("The sum of negative numbers is", n, "\nThe sum of positive even numbers is", pe, "\nThe sum of positive odd numbers is", po)
Ralf
  • 16,086
  • 4
  • 44
  • 68