How to execute my code using terminal without terminal being occupied

Solution 1:

You should realize that the Linux terminal (bash) is capable of multitasking, so the terminal is never truly "occupied". By default you can suspend a running program with Ctrl + Z (sending stty susp).

But it can be even simpler to run the script in the background.

python3 main.py &

You can then later give it foreground focus with the fg command. This is basic job control.

If you additionally want to run the script so it isn't attached to the current terminal (and doesn't exit when you close it), use the nohup command:

nohup python3 main.py &