not completed but commiting anyway

So the error's a bit difficult to get but let me try to unpack it.

Your else is on the outside if statement, where pincipal is being tested. That means that it only triggers if one of the principals doesn't match. But in this case it's one of the inner if stattements probably a 1,000,000+ value for 30 years or something similar. Because the else is on the outside, it doesn't catch that problem.

A better solution is starting with rate = None before the if's begin. Then you don't need the else, or the `if rate is None` block. Just `return rate`