How to make a loop that stay during the whole code end when a value = 0 (resolved)

How sorry the title might sounds unclear so I’ll explain more.

Here is my code (I removed all text insides ’ ’ so it’s readable):

choice1 = input(' ')
if choice1.lower() == ' ':
    p1_choice2 = input(' ')
    
    if p1_choice2.lower() == '':
        p1_choice3 = input(' ')
    elif p1_choice2.lower() == ' ':
        p1_choice4 = input(' ')

        if p1_choice4.lower == '  ':
            print(' ')
            print(' ')
        elif p1_choice4.lower == '  ':
                p1_choice6 = input(' ')

It’s a choice based game and some choice makes you lose HP. HP is set randomly by “MC_HP = random.randint(2, 8)” before the start of the endless “if” and “elif” loop.

How can I make it so if line 58 makes you lose all your HP, and there is more than 100 lines left of “if” and “elif”, the code end and print “You lost all your HP and died. -THE END_”?

Is doing “MC_HP = MC_HP - 1” in an if statement after an input (choice) will impact the random MC_HP set at the beginning?

Thank you, I’ll be very grateful if you can help me.
[I am a newbie]

Well, one thing you can do is add the sys module to your program:

#at the top of file
import sys

and then when you want to send your player off of this valley of tears:

print("You Lost!")
sys.exit(0)

:smiling_face:

1 Like

Oh interesting, I’ll try to write some code with that to see if I can make it work.

Ok wow it worked thank you!

1 Like