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!
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
@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
Also, you really should add better option detection, like if a option is not valid, you say so.
And maybe you should add dictionaries. I used to love to do text adventures, then I realized dictionaries were simple combined with arrays.
@ebest I tested it out, but if I get a wrong answer, (but then get one correct and move on) and then do the same thing again, Then instead of having only one life, I have 2. How do I fix this? (If you can't understand my question, try getting one wrong and then correct twice in a row, then get it wrong. Instead of ending it it gives another chance.)