# We have now written a __str__ method and prepared to
# write a __repr__ method.  We also used the silly method
# sing to understand "self".

from math import sqrt

class Point:
    """
    A n-dimensional point.
    coords is a list of numbers containing the coordinates
    of this Point.
    """

    def __init__(self, coords):
        """
        Correction:
        (Point, list of number) -> NoneType
        
        Initialize this point with these coords.
        We will return to this docstring to add an example
        showing that p is as it should be.
        
        >>> p = Point([3, 4.0, 5.32, 6, 7])
        >>> p.coords
        [3, 4.0, 5.32, 6, 7]
        """
    
        self.coords = coords
    
    
    def distance_from_origin(self):
        """
        (Point) -> float
    
        Return the distance from this Point to the
        origin.
        
        >>> p = Point([3, 4])
        >>> p.distance_from_origin()
        5.0
        """
        
        sum_of_squares = 0
        for coord in self.coords:
            sum_of_squares += coord**2
        return sqrt(sum_of_squares)
    
    def __str__(self):
        """
        (Point) -> str
        
        Return a convenient str representation of this Point.
        
        >>> p = Point([3.0, 4.0])
        >>> print(p)
        (3.0, 4.0)
        >>> p.__str__()
        '(3.0, 4.0)'
        >>> str(p)
        '(3.0, 4.0)'
        """
        
        return str(tuple(self.coords))
    
    def __repr__(self):
        """
        (Point) -> str
        
        xxx
        
        >>> p1 = Point([6, 1, 2])
        >>> p2 = eval(repr(p1))
        >>> p2 == p1
        True
        
        """
        
        # Our next job: Write a body that passes the doctest.
        
    
    def sing(self, punctuation):
        """
        (Point, str) -> NoneType
        
        A silly method used in explaining the parameter "self".
        """
        
        for c in self.coords:
            print("{}{}".format(c, punctuation))    
    
if __name__ == '__main__':
    import doctest
    doctest.testmod()
