0

The program won't end when I try to get it to end with a sys.end command

I have tried to use sys.end with this line but it does not work

if answers2 == "YOUR ATTACK MISSES AND YOU DIE! RESTART GAME"
    sys.end

and here is this code

#here is where I want the different options to be! I set it up like this for random options
answers1 = [
    "A BIG SPIDER COMES AT YOU! WHAT DO YOU DO?",
    "A GOBLIN COMES AT YOU! WHAT DO YOU DO?",
    "A GHOST COMES AT YOU! WHAT DO YOU DO?",
    "AN UNDEAD COMES AT YOU! WHAT DO YOU DO?",
    "AN ASSASSIN COMES AT YOU! WHAT DO YOU DO?"

]

answers2 = [
    "YOUR ATTACK MISSES AND YOU DIE! RESTART GAME",
    "YOUR ATTACK HITS! MOVING ON"
]


if attack1.lower().strip() == "attack":
    print random.choice(answers2)
    # right here is where I want to have it so if you get "YOUR ATTACK MISSES AND YOU DIE!" you stop the game

^^^ here are the different options for what is to happen

if you need the whole code just let me know! I'm new to this website!

I expect the output to end the program but the program just keeps going

Just letting you know, I am really new to python so please be patient

  • Does this answer your question? [Terminating a Python script](https://stackoverflow.com/questions/73663/terminating-a-python-script) – RoyM Nov 03 '19 at 00:52
  • I flagged this as a duplicate since there are many threads on python exit codes. But, in short, you should set a variable `choice = random.choise(answsers2)`, and then check if this variable equals your string, then do something. – RoyM Nov 03 '19 at 00:55

0 Answers0