*Very* nice use of assert. I would have probably put it first, though. If you're gonna check it, you might as well check it before you've actually done any other computation.