Dark theme

One example of where this would be useful is at the start if they don't go into the mine:

decision = input("Do you want to enter? [Y,N]: ")
if decision == "N":
    print("Your quest is at an end, goodbye!")
    sys.exit()
else:
    print("You enter the mines.")
print("The way is lit by candles on the wall.")

Try adding this code to our game and check it works.

Note that when we use functions from libraries we need to use the dot operator "." - this means "look inside and find", so sys.exit() means "look inside the system library and find the exit() function.

Go through and add exit() commands wherever you think they might be useful - but check and make sure the other options still work - one missed indent could have everyone exiting! You only need to do the "import sys" once, at the top of the file.

[Home > Part 2 > Next]