python中IF-ELSE语句的else的语法错误

时间:2013-07-18 08:16:32

标签: python if-statement python-3.x syntax-error

我在这个特定的“其他”上不断收到语法错误。我不知道问题是什么。如果它已经不够清楚了,那就是第16行的其他内容。我几天前刚刚开始使用python。所以,请不要太过努力。

W = 1
while W == 1:
    if MH > 0:
        PlayerInput = input("Attack, Defend, or Run('1','2',or'3'):")
        if PlayerInput == "3":
            W = 0
        elif PlayerInput == "1": #Attack
            Atk = randint(1,4)
            if Atk == 1:
                Atk = randint(1,4)
                if Atk == 1:
                    print ("Miss")
                else:
                    MH = MH-((1/2)*FightingAbility)        
                    print ("Enemy lost %s Health" % ((1/2)*FightingAbility)
            else:<<<<---------[[This else is giving me trouble]]
                MH = MH-Fightingability
                print ("Enemy lost %s Health" % (FightingAbility))
        elif PlayerInput == "2": #Defend   
            if S > FightingAbility: #Enemy is stronger
                Def = randint(1,4)
                if Def == 1:
                    Def = randint(1,4)
                    if Def == 1:
                        print ("The %s Missed" % (E))
                    else:
                        Health = Health-((1/2)*S)        
                        print ("You lost %s Health" % ((1/2)*S)
                else:
                    Health = Health-S
                    print ("You lost %s Health" % (S))
            elif S <= FightingAbility: #Enemy is weaker
                Def = randint(1,4)
                if Def == 1:
                    Def = randint(1,4)
                    if Def == 1:
                        Health = Health-S
                        print ("You lost %s Health" % (S))
                    else:
                        Health = Health-((1/2)*S)        
                        print ("You lost %s Health" % ((1/2)*S)
                else:
                    print ("The %s Missed" % (E))
    else:
        Win=1
        pass

1 个答案:

答案 0 :(得分:2)

print行(在else之前)没有右括号。

print ("Enemy lost %s Health" % ((1/2)*FightingAbility)