jeudi 28 octobre 2021

Why is my else statement triggering sometimes but not always?

I am attempting to make an adventure game with some combat in it.

However, the

else:
    print("The werewolf took " + str(damage) + " damage. " + str(werewolf_health) + " health remains.") 

trigger (and the code beneath it) only triggers sometimes. Can you help me out with why?

This is the code:

def attack():
    werewolf_health = 100
    user_health = 100
    while werewolf_health > 0:
        attack = input(">").upper()
        if "ATTACK" in attack:
            damage = rand_int()
            damage2 = rand_int_werewolf()
            if damage == 20:
                print(random.choice(sword_crit))
                damage = damage * 1.5
                werewolf_health = werewolf_health - damage
                print("The werewolf took " + str(damage) + " damage. " + str(werewolf_health) + " health remains.")
                if werewolf_health <= 0:
                    print(random.choice(werewolf_death))
                    resolution()
            elif 17 <= damage <= 19:
                print(random.choice(sword_above_avg))
                werewolf_health = werewolf_health - damage
                print("The werewolf took " + str(damage) + " damage. " + str(werewolf_health) + " health remains.")
                if werewolf_health <= 0:
                    print(random.choice(werewolf_death))
                    resolution()
            elif 6 <= damage <= 16:
                print(random.choice(sword_avg))
                werewolf_health = werewolf_health - damage
                if werewolf_health <= 0:
                    print(random.choice(werewolf_death))
                    resolution()
                else:
                    print("The werewolf took " + str(damage) + " damage. " + str(werewolf_health) + " health remains.")
                    damage2 = rand_int_werewolf()
                    if damage2 == 20:
                        print(random.choice(werewolf_crit))
                        damage2 = damage2 * 1.5
                        user_health = user_health - damage2
                        print("You take " + str(damage2) + " damage. " + "Your health drops to " + str(
                            user_health) + ".")

Aucun commentaire:

Enregistrer un commentaire