Define a List of Points

  1. Design a class MyPoint, whose attributes include:
  2. Ask the user to supply a filename, which stores the coordinates of a few points. For example, (1, 2), (2, 7), (3, 4), (12, 5), (6, 8) may be stored as
    
    1 2
    2 7
    3 4
    12 5
    6 8
    
    
  3. Create a list to store these points.
  4. Print out the items in this list as follows.
    
    (1,2) 2.23606797749979
    (2,7) 7.280109889280518
    (3,4) 5.0
    (12,5) 13.0
    (6,8) 10.0
    
    
  5. Note: You have to define the __str__() function in the class, which will convert an object into a string (see P.360). Otherwise, when you try to print out an object, you will get an output like <__main__.MyPoint object at 0x801b6ffd0>.
  6. You may test your class definition with the following main() function:
    
    def main():
        filename = input("Enter the name of the data file: ")
        myPoints = readPoints(filename)
        for p in myPoints:
    	print( p, p.distance() )