除ValueError之外的语法无效

时间:2014-11-11 15:29:17

标签: python python-3.3 except

当我运行此代码(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")

我说“语法无效”,它突出显示“如果回答== c:”红色的冒号。

1 个答案:

答案 0 :(得分:1)

您缺少右括号:

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