Do you use an editor to enter Python code? If not, by all means do that, the interactive mode isn't intended to write more than 4 lines of code, for testing!
If you do use an editor, the editor would do such functionality, Python itself can only 'run' code, the Python-editor (which is a separate program) shows the code, and let's you edit save and load it. Unfortunately, I have never seen any editor that does what you want.
In what way do you get lost? Maybe you can figure out a way to setup your code in a less confusing way?
One option that should work is to add "# end if" lines or "#end while" lines with the correct indentation. The disadvantage of that solution is that nobody else does that afaik, so you'd still get lost with code by others.
If you do use an editor, the editor would do such functionality, Python itself can only 'run' code, the Python-editor (which is a separate program) shows the code, and let's you edit save and load it.
Unfortunately, I have never seen any editor that does what you want.
Building on this response, I've also not seen an editor that highlights blocks quite like this. The most similar thing I have seen are "indentation guides" -- lines or colored columns placed at each level of indentation. You can see if there are settings or plugins that enable indentation guides in the editor of your choice.