As the program terminates, all of the assigned memory is cleared, including the running state.
So what can you do?
Save the state than you want and store it in permanent storage that survives the execution of the program. So not in memory, but for instance on disc or in an online service. Let's stick with the disc as the most obvious choice.
You'll need to look into file management with Python. How to save content to a file, and how to load content from a file.
Look into this tutorial, start with open() then check out read() and write().
Good luck!
Note: any file created should be added to your OnlineGDB project to prevent the server from removing resources after you're done with your work. Running things on your local PC does not need such considerations. ;)