Help! How do you add lives in code!
kirbyfire (1)

Right now, I am starting to work on a project, (no animations, all just text), Can someone tell me how I can make a life system so If you get an incorrect answer, you lose a life? This is in Python. Thanks!

You are viewing a single comment. View All
Answered by ebest (590) [earned 5 cycles]
View Answer
mwilki7 (519)

Just stick it in a variable and check for correct answer:
Fill in "correct option" with whatever condition you think is the correct option

player_health = 5
...
...
y = input("....A) Good option B) Bad option C) Bad Option")
if y=="a":
    # good option!
    # do other stuff here I guess
else:
    # bad option!
    # decrease health by 1
    player_health = player_health - 1

if player_health == 0:
    # game over, health zero!
else:
    # still alive
ebest (590)

@mwilki7 Change that to (little change)

import sys
player_health = 5
...
...
y = input("....A) Good option B) Bad option C) Bad Option")
if y=="a":
    # good option!
    # do other stuff here I guess
    pass
else:
    # bad option!
    # decrease health by 1
    player_health -= 1

if player_health == 0:
    #Game over, health zero!
    print("Game over!")
    sys.exit()
else:
    # still alive
    pass
kirbyfire (1)

@mwilki7 THANK YOU SO MUCH YOU ARE A GOD AND A LIFESAVER!!!!!!!!