I'm making a mini python based game where if the game is lost I ask the user to 'rerun the program' to play the game again.
I'm trying to find a more elegant way to achieve this using code. Is there a way I can do this programmatically? It'd require the program to close and reopen, or restart the program and I can manually reset the variable values.
Here's what I've got so far:
restart = input("\nDo you want to restart the program? [y/n] > ")
if restart == "y":
os.execl(sys.executable, os.path.abspath(__file__), *sys.argv)
else:
print("\nThe programm will be closed...")
sys.exit(0)
Found this online but can't seem to get it to work.