from math import sqrt

class Point:
    """n-dimensional point
    """

    def __init__(self, coord):
        """ (Point, list-of-floats) -> NoneType

        Create and initialize this point.

        >>> p = Point([3, 4])
        """
        # list comprehensions --- [<expression> for x in iterable]
        # may be something new to you
        self.coord = [float(x) for x in coord]
    
    def distance_to_origin(self):
        """ (Point) -> float

        Distance from self to origin.

        >>> p = Point([3, 4])
        >>> p.distance_to_origin()
        5.0
        """
        return ( # square root of...
            sum( # the sum of...
                # squares of elements of self.coord
                [x**2 for x in self.coord]))**(1/2)

    def __eq__(self, other):
        """ (Point, object) -> bool

        Return whether self is equivalent to other.

        >>> p1 = Point([3, 4, 5])
        >>> p2 = Point([3.0, 4.0, 5.0])
        >>> p1 == p2
        True
        """
        return (isinstance(other, Point) and # make sure other's a Point and
                self.coord == other.coord) # make sure coords are equivalent)

    def _set_coord(self, coord):
        """ (Point, list-of-floats) -> NoneType

        Set coordinates for this point.
        """
        if '_coord' in dir(self): # has _coord already been set?
            raise Exception('Cannot reset coords')
        else: # if not already set, go ahead!
            self._coord = coord

    def _get_coord(self):
        """ (Point) -> list-of-floats

        Return coordinates for self.
        """
        return self._coord
        
    # Access to coord is delegated to property, so get_coord
    # and set_coord are called instead
    coord = property(_get_coord, _set_coord, None, None)

if __name__ == '__main__':
    import doctest
    doctest.testmod()
