Start of code review

Use custom exceptions for control flow
You probably don't want to use assertion errors for this kind of control flow because assertions get optimized away if you run your program with the -O flag. Instead, define a custom exception that inherits from Exception and raise it.