Dec-14-2020, 07:46 PM
Hi, I have been doing well on Python coding so far but now Im stuck on this assignment.
'''This class represents regular polygons. The initialization method
creates a regular polygon with a set number of sides of a given length.
The default constructor creates an equilateral triangle of side length 1.
There are methods for changing the length or number of sides, calculating
the perimeter and area of a RegularPolygon object, and printing a string
representation of a RegularPolygon object'''
You will need the following six methods
__init__
addSides
setLength
getPerimeter
getArea
toString
The formula for the area of a regular polygon is as follows (A is area, l is length, and n is the number of sides):
Please note that 180/n is a degree measurement that needs to be converted to radians. The math module has a tan() method and a radians method (math.tan() and math.radians(), respectively).
This is what I have so far
'''This class represents regular polygons. The initialization method
creates a regular polygon with a set number of sides of a given length.
The default constructor creates an equilateral triangle of side length 1.
There are methods for changing the length or number of sides, calculating
the perimeter and area of a RegularPolygon object, and printing a string
representation of a RegularPolygon object'''
You will need the following six methods
__init__
addSides
setLength
getPerimeter
getArea
toString
The formula for the area of a regular polygon is as follows (A is area, l is length, and n is the number of sides):
Please note that 180/n is a degree measurement that needs to be converted to radians. The math module has a tan() method and a radians method (math.tan() and math.radians(), respectively).
This is what I have so far
import math class RegularPolygon: def __init__(self, n = 1, l = 1): self.__n = n self.__l = l def addSides(self, x): x = self.__n + x def setLength(self, l ): self._l = l def setPerimeter(self): return (self.__n * self.__l ) def getArea(self): return def toString(self): return demo_object = RegularPolygon (3, 3) print(demo_object.self.__n() , demo_object.self__l())