[Tutor] line class

John Fouhy john at fouhy.net
Tue Jul 8 07:10:50 CEST 2008


On 08/07/2008, Christopher Spears <cspears2002 at yahoo.com> wrote:
>  Basically, if the two the x values are the same, I will get a ZeroDivisionError.  A line in this
> case would simply point straight up.  What would slope be in this case?  I will admit that
> this is probably a math problem not a programming one, but I decided to run it by you
> anyway.

The slope in this case is undefined.  Throwing an exception seems to
be a pretty reasonable way of dealing with this case, to be honest.
(although if you're keen, you could define your own
"UndefinedSlopeError" or "VerticalLineError" exception and raise that
instead of the ZeroDivisionError)

-- 
John.


More information about the Tutor mailing list