在python脚本中获取语法错误

时间:2014-12-03 00:48:32

标签: if-statement syntax syntax-error comparison-operators

我一直在看似没有错误的语法错误。它是在带有和比较的if语句中引起的,我不知道为什么。这也是我使用python的第一个学期所以请帮助。

while userWins < 2 or CPUWins < 2:
    answer = random.randrange(3)
    print(str(answer))
    print("[1]-- Rock")
    print("[2]-- Paper")
    print("[3}-- Scissors")
    guess = int(input("Enter a number corresponding to a choice.")
    if guess == 1 and answer == 3:  #<--This is the line that keeps getting the syntax error
        userWins = userWins + 1
        print(name, " wins that round")
        RoundScore(userWins, CPUWins, name)
    elif guess == 1 and answer = 2:
        CPUWins += 1
        print(name, " loses that round")
        RoundScore(userWins, CPUWins, name)

这是IDLE给我的错误

追踪(最近一次通话):   文件&#34; E:/Cosc-151/Assignment5/a5_v34.py" ;,第1行,在     导入Mods   文件&#34; E:/ Cosc-151 / Assignment5 \ Mods.py&#34;,第61行     如果猜= = 1并回答== 3:                                  ^ SyntaxError:语法无效

感谢

1 个答案:

答案 0 :(得分:3)

您错过了上一行的关闭点(关闭int来电)。

在您需要之前的行

guess = int(input("Enter a number corresponding to a choice."))
                                                              ^
                                                       You forgot this