I am trying to create a polygon class that returns the area and perimeter when given the sides and length from user input. However, it doesn't take the two variables I'm trying to pass into the __init__
method. The sides and length must be private and must be received through user input.
import math
class Polygon:
use = (input("Enter in the sides and length of sides seperated by a comma"))
ans = use.split(",")
__numofSides = ans[0]
__sideLength = ans[1]
def __init__(self, __numofSides, __sideLength):
self.__numofSides = __numofSides
self.__sideLength = __sideLength
def get__numofSides(self):
self.__numofSides = ans[0]
return __numofSides
def get__sideLength(self):
self.__sideLength = ans[1]
return __sideLength
def perimeter(self, __numofSides,__sideLength):
peri = self. __numofSides * self.__sideLength
return peri
def area(self, __numofSides, __sideLength):
area = (((__sideLength **2) * __numofSides) / (tan(4) *(math.pi/__numofSides)))
return area
def __str___(self,):
print("Number of Sides: {}\n Length of Sides: {}\n" \
"Perimeter is: {}\n Area is: {}".format(__numofSides,__sideLength,peri,area))
def main():
p1 = Polygon()
p1.perimeter()
p1.area()
p1.__str__()
main()