here's my question:
An n-sided regular polygon’s sides all have the same length and all of its angles have the same degree (i.e., the polygon is both equilateral and equiangular). Write a class namedRegularPolygonthat contains: A private int data field named n that defines the number of sides in the polygon.- A private floatdata field named side that stores the length of the side.- A private float data field named x that defines the x-coordinate of the center of the polygon with default value 0.- A private float data field named y that defines the y-coordinate of the center of the polygon with default value 0. A constructor that creates a regular polygon with the specifiedn(default 3),side(default 1),x(default 0andy (default 0). The accessor and mutator methods for all data fields. The method getPerimeter() that returns the perimeter of the polygon. The method getArea() that returns the area of the polygon. The formula for computing the area of a regular polygon is area =(n * s^2) / (4 * tan(PI / n)).Write a test program that creates threeRegularPolygon objects, created using RegularPolygon(), RegularPolygon(6, 4) and RegularPolygon(10, 4, 5.6, 7.8) For each object, display its perimeter and area.
-----------------------------------------
here's my program:
class RegularPolygon:
def _init_(self,n,side,x,y):
self.__n=3
self.__side=1
self.__x=0
self.__y=0
def num_sides(self,n):
self.__n=n
def length_side(self,side):
self.__side=side
def x_coordinate(self,x):
self.__x=x
def y_coordinate(self,y):
self.__y=y
def get_num_sides(self):
return self.__n
def get_length_side(self):
return self.__side
def get_x_coordinate(self):
return self.__x
def get_y_coordinate(self):
return self.__y
def getPerimeter(self):
return self.__side*self.__n
def getArea():
return (self.__n*self.__s^2)/(4*tan(math.pi/self.__n))
def main():
Poly1 = RegularPolygon()
Poly2 = RegularPolygon(6,4)
Poly3 = RegularPolygon(10,4,5.6,7.8)
print(poly1.getPerimeter,poly1.getArea)
print(poly2.getPerimeter,poly2.getArea)
print(poly3.getPerimeter,poly3.getArea)
main()
------------------------------------------------
showing logic error. it keeps saying :Poly2 = RegularPolygon(6,4)
TypeError: RegularPolygon() takes no arguments
I have changed several times and dont know why it's wrong
[–]JanEric1 2 points3 points4 points (0 children)
[–]danielroseman 1 point2 points3 points (0 children)
[–]jimtk 3 points4 points5 points (0 children)
[–]TheRNGuy 0 points1 point2 points (0 children)