How do I reset the code

how do i reset the code in Python, like how you do exit() but to restart, how? reset() or restart() don’t work.

like i want to do this:

if activate == start:
    ...
else:
    reset()

and i want It to like reset the code, so if there’s a print before that It shows the print And so on

PS: im a beginner, started a week ago

Hi @paolaccialesssn, welcome!

You can create a forever loop and use the continue keyword to reset it.

while 1:
    ...
    if activate == start:
        ...
        break
    else: continue

break stops the program so it doesn’t loop forever.

7 Likes

You could probably do something like this:

def main():
    # Put all your code in here
def restart():
    main()
    exit()
main()

Then anytime you need your code to restart, just call restart (Note that variables will not be saved between loops, and if you do this too many times the code will crash due to a recursion limit.)

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.