Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why isn't elif working? Is it elif or is it the loop that I'm messing up?

I can’t get my code to use the bunkerdown or eject inputs, I tried recreating the problem but I can get anything.
Here’s all the relevant code, if it’s something obvious I apologize I’m new.

fight = 10
wind_up = 15
bunker_down = 0.5
life = 80
dmg_reduction = float(1)
damage_bonus_active = False
damage_bonus = 0
rabbit_health = 30

while rabbit_health > 0:
    enemy_dmg = random.randint (5,12)
    life = life - enemy_dmg * dmg_reduction
    dmg_reduction = 1
    if life <= 0:
        print("You failed, die")
        exit()
    print("You've been hit, lose " + str(enemy_dmg * dmg_reduction) + " Health. " + str(life) + "/80")
    action = input("Fight, Windup, Bunkerdown ")
    if action.upper() == "FIGHT":
        rabbit_health = rabbit_health - fight + damage_bonus
        print("You hit the Rabbit for " + str(fight + damage_bonus) + " HP!")
        damage_bonus = 0
        damage_bonus_active = False
    elif action.upper() == "WINDUP" or "WIND UP":
        if damage_bonus_active is False:
            damage_bonus += wind_up
            print("You Wind up for " + str(wind_up) + " more Damage on your next attack!")
            damage_bonus_active = True
        else:
            print("You just wasted a turn, Moron!")
    elif action.upper() == "BUNKERDOWN" or "BUNKER DOWN":
        dmg_reduction = dmg_reduction - bunker_down
        print("Brace for Impact!")
    elif action == "eject":
        print("ejected")
        exit()
    else:
        print("You just wasted a turn, Moron!")
print("winner!")

I tried to recreate the problem with this block of code but I can’t seem to get it to fail.

testV1 = False
insert = input("insert ")
if insert.upper() == "INSERT":
    print("con1")
elif insert.upper() == "DN":
    print("con2")
elif insert.upper() == "ND":
    if testV1 is False:
        print("bank")
        testV1 = True
    else:
        print("F")
elif insert.upper() == "LL" or "L L":
    print("con4")
else:
    print("false")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

action.upper() == "WINDUP" or "WIND UP"

means

( action.upper() == "WINDUP" ) or "WIND UP"

The whole will always result in a true value because "WIND UP" is a true value.

You want

action.upper() == "WINDUP" or action.upper() == "WIND UP" 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading