How to you get a program to stop running in python?

I am trying to do a text adventure game with multiple adventures. When I try to end an adventure, it just starts another one. How do I make the program to stop running when one adventure ends?

2 Likes

Welcome to the community, @Salmaan-B!

The number of solutions depend on how you built your code, but if you want to end your program instantly, which is not the best practice IMO, you can just use exit()

Also, like I said, this works but isn’t the best practice. You should end your code naturally if possible. Can you provide a link to your Repl or paste your code in a reply?

https://replit.com/@Salmaan-B/Big-Text-Adventure-Game#main.py

Yeah, it seems to me that it would be a lot of work to refactor your code to let it end naturally, so I would just use exit() in this scenario.

Or you know, you can just use

exit()
2 Likes

That works with scripts? Thought that was a shell-only thing. Well, you learn something new every day. I’ll edit my replies now.

2 Likes

Just use exit() it’s a text adventure game, as long as you aren’t opening files and then not closing them or something it isn’t going to cause issues.

Besides exit(status), you can use quit().