Invalid syntax for except ValueError

635 views Asked by At

When i run this code (Python 3.3):

counter=0
score=0
import random
a = random.randint(1,25)
b = random.randint(1,25)
c=a+b
try:
    answer=int(input("What is "+str(a)+" + "+str(b)+" ? ")                
    if answer == c:
        score=score+1
        print("Well done!")
        print("Your score is "+str(score)+".")
        print("")
        counter = counter + 1
    else:
        print("Thats wrong. The correct asnwer is: "+str(c)+".")
        print("Your score is "+str(score)+".")
        print("")
        counter = counter + 1
except ValueError:
       print("sadas")

I says "invalid syntax" and it highlight the colon from "if answer == c:" red.

1

There are 1 answers

1
Martijn Pieters On BEST ANSWER

You are missing a closing parenthesis:

answer=int(input("What is "+str(a)+" + "+str(b)+" ? ")                
#         ^     ^                                    ^?
#         |      \----------------------------------/ |
#          \-----------------------------------------/