SyntaxError: unexpected EOF while parsing

Quar picture Quar · May 2, 2013 · Viewed 168.6k times · Source

I have no idea why this does not work please help

import random
x = 0
z = input('?')
int(z)

def main():
    while x < z:
        n1 = random.randrange(1,3)
        n2 = random.randrange(1,3)
        t1 = n1+n2
        print('{0}+{1}={2}'.format(n1,n2,t1)

When i run this it outputs this error

File "/Users/macbook/Documents/workspace/gamlir_filar/samlagning.py", line 12

                                                ^
SyntaxError: unexpected EOF while parsing

I am using eclipse and python 3.3 and i have no idea why this happens. It sometimes outputs errors like this.

Answer

Ashwini Chaudhary picture Ashwini Chaudhary · May 2, 2013

You're missing a closing parenthesis ) in print():

print('{0}+{1}={2}'.format(n1,n2,t1))

and you're also not storing the returned value from int(), so z is still a string.

z = input('?')
z = int(z)

or simply:

z = int(input('?'))