0

Code :

    n,X=input(),0
    for t in range(int(n)):
        eval(input())
    print(X)

Traceback (most recent call last):
  File "prog.py", line 3, in <module>
    eval(input())
  File "<string>", line 1
    X++
      ^
SyntaxError: unexpected EOF while parsing

Using raw_input instead of input() in the only solution I am able to find but in python 3.x input is raw_input(): How do I use raw_input in Python 3

any other method?

FYI; I am trying to solve: http://codeforces.com/problemset/problem/282/A

Community
  • 1
  • 1
shifu
  • 6,586
  • 5
  • 21
  • 21

1 Answers1

0

Remove the eval() call.

input() in Python 2 is the equivalent of eval(input()) in Python 3, and if you need to use raw_input() in Python 2 then in Python 3 you need to remove the eval() call.

You'll have to parse the input yourself; ++ is not a valid Python operator, you cannot use eval() to solve that Codeforces problem.

The simplest way to solve the posted problem is to read the input line by line:

import sys, itertools

count = int(next(sys.stdin))
x = 0
for line in itertools.islice(sys.stdin, count):
    x += 1 if '++' in line else -1
print(x)
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343