I was primarily offended by the second code snippet, in which there is a variable named foundException but it is not an exception.
I didn't realize it was Sage (I didn't know that existed) but I'm not sure that actually makes a difference. Obviously it works, and that's fine, but it's still horribly ugly.
They don't mean "found an execution exception", they literally mean that the code found an exception to the rule that n^9 + 4n^6 + n^5 + 2n^3 is divisible by 8.
I didn't realize it was Sage (I didn't know that existed) but I'm not sure that actually makes a difference. Obviously it works, and that's fine, but it's still horribly ugly.