This is my code:
sleep = input("Commander, would you like to sleep now? If yes then we can take out your bed. ")
if sleep == "yes":
Energy = Energy + 5
print("We have taken out your bed. The spaceship is on autopilot and you may now sleep.")
time.sleep(4)
print("2 weeks later...")
else:
Energy = Energy - 5
print("Ok. It is all your choice. BUT you WILL lose energy. Lets carry on with the journey. You have",Energy,"energy remaining.")
time.sleep(4)
print("Commander, you have been extremely successful so far. Well done and keep it up!")
time.sleep(6)
direction = input("Oh no Sir! There is trouble ahead! Please make your decision quick. It's a matter of life and death. It is also a matter of chance! There are many asteroids ahead. You may either go forwards, backwards, left or right. Make your decision...before it's too late! ")
if direction == "left":
Coins = Coins + 15
Fuel = Fuel - 15
while True:
print ("You have managed to pass the asteroids, you may now carry on. You have",Fuel,"fuel left.")
break
continue
elif direction == "backwards":
print("You have retreated and gone back to Earth. You will have to start your mission all over again.")
time.sleep(2.5)
print("The game will now restart.")
time.sleep(2)
print("Please wait...\n"*3)
time.sleep(5)
keep_playing = True
while True:
script()
elif direction == "forwards":
Fails = Fails + 1
print("You have crashed and passed away. Your bravery will always be remembered even if you did fail terribly. You have failed",Fails,"times.")
time.sleep(3)
ans = input("Do you want to play again? ")
if ans == "yes":
time.sleep(3)
script()
else:
print("Our Earth is now an alien world...")
# Program stop here...
On the last line I want the program to stop: print("Our Earth is now an alien world...")
However, I know that there are ways to stop like quit(),exit(), sys.exit(), os._exit(). The problem is that sys.exit() stops the code but with the following exception message:
Traceback (most recent call last):
File "C:\Users\MEERJULHASH\Documents\lazy", line 5, in <module>
sys.exit()
SystemExit
On the other hand when I try to use the os._exit() on that last line line of code an error message comes up stating that TypeError: _exit() takes exactly 1 argument (0 given). exit() and quit() are not recommended for production code.
My question: are there any exiting commands that stop your code from carrying on without showing any message or ending with >>> or that it just closes the program?