python中IFELSE语句的else语法错误

2024-09-27 00:16:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在这个特定的“else”上得到一个语法错误。我不知道是什么问题。如果还不够清楚,那就是第16行的else。我几天前刚开始使用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

Tags: youifisdefelseprintrandinthealth

热门问题