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
ebest (574)

@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