50.6k views
5 votes
Consider the following class which is used to represent a polygon consisting of an arbitrary number of (x, y) points:

class Polygon :
def __init__(self) :
self._x_points = []
self._y_points = []

User Snookian
by
6.2k points

1 Answer

4 votes

Answer:

The init method of the Polygon class defines two attributes 'x' and 'y' which are both lists. To add points to the lists x and y, define the add_point method;

def add_point(self, x, y) :

self._x_points.append(x)

self._y_points.append(y)

Step-by-step explanation:

A class is a blueprint of a data structure. It contains the attributes and methods of the data structure type. Attributes are features of a data structure defined as variables that can be either a class attribute or an attribute of the instance of the class object. A method is just a function defined in a class.

The add_point method in the polygon class accepts two parameters and appends the values to the x and y lists defined in the init method.

User Isitar
by
5.9k points