On Tue, Jul 8, 2008 at 12:52 AM, Christopher Spears
<[EMAIL PROTECTED]> wrote:
> For problem 13-6 out of Core Python Programming, I created a line class that 
> consists of two points.  The line class has the following methods: __repr__, 
> length, and slope.  Here is the code:

>    def __repr__(self):
>        coord = (self.x,self.y)
>        return coord

This should be return str(coord); __repr__() should return a string,
not a tuple.

> 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 is infinity (or undefined). On some platforms and Python
versions you can use float('inf') to represent positive infinity so
you could return that if it is supported.
http://www.python.org/dev/peps/pep-0754/ (note this PEP was rejected)

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to