#### Can anyone help me understand a part of the code in this Triangle Class?

``````filledTrue = (filled == 1)
``````

``````class GeometricObject:
def __init__(self, color =  "green" , filled = True):
self.__color = color
self.__filled = filled

def getColor(self):
return self.__color

def setColor(self, color):
self.__color = color

def isFilled(self):
return self.__filled

def setFilled(self, filled):
self.__filled = filled

def __str__(self):
return  "color: "  + self.__color + \
" and filled: "  + str(self.__filled)

class Triangle(GeometricObject):
def __init__(self, side1 = 1.0 , side2 = 1.0, side3 = 1.0):
super().__init__()
self.__side1 = side1
self.__side2 = side2
self.__side3 = side3

def getSide1(self):
return self.__side1

def setSide1(self, side1):
self.__side1 = side1

def getSide2(self):
return self.__side2

def setSide2(self, side2):
self.__side2 = side2

def getSide3(self):
return self.__side3

def setSide3(self, side3):
self.__side3 = side3

def setArea(self):
self.area = area

def getArea(self):
s = (self.__side1 + self.__side2 + self.__side3) / 2
area = (s * (s - self.__side1) * (s - self.__side2) * (s - self.__side3)) ** 0.5
return area

def getPerimeter(self):
perimeter = self.__side1 + self.__side2 + self.__side3
return  perimeter

def triangleString(self):
return "Triangle: Side 1: " + self.__side1 + "Side 2: " + self.__side2 + "Side 3: " + self.__side3

def main():
side1 = eval(input("Enter a number for side 1: "))
side2 = eval(input("Enter a number for side 2: "))
side3 = eval(input("Enter a number for side 3: "))
color = input("Enter a color for the triangle: ")
filled = eval(input("To fill the triangle, enter 1, otherwise enter 0: "))
filledTrue = (filled == 1)
#set the variables in the classes
triangleSolution = Triangle(side1, side2, side3)  # this sets the triangle sides in Triangle Class
triangleSolution.setColor(color)  # this sets the color in the superclass (through subclass)
triangleSolution.setFilled(filledTrue) # this sets the fill
#get the variables in the classes with printout
print("The triangle’s area is: ", triangleSolution.getArea(), '\n',
"The perimeter is: ", triangleSolution.getPerimeter(), '\n',
"The color is: ", triangleSolution.getColor(), '\n',
"The color is filled: ", triangleSolution.isFilled())

main()
``````
1 个回复

``````x = 1==1 # True
y = 'a'=='b' # False
z = 2 <= 5 # True
``````
1 谁能帮助我理解这段代码？

2 我正在尝试这个多线程代码来理解。 谁能帮助我理解“打印消息”部分。 我在此发布代码

2016-02-29 01:47:32 1 32   c/ sockets
3 谁能帮助我理解这个asm代码（很简单）

2011-02-15 12:29:14 2 800   debian
4 谁能帮助我理解此代码（在lxml，python中解析HTML表）？

5 谁能帮助我优化代码？

2015-10-22 10:34:05 1 36   python
6 谁能帮助我理解此递归序言示例？

8 请帮助我理解代码

2013-06-05 04:09:22 1 122   java
9 谁能帮助我修改Java代码？

2011-04-21 05:59:52 2 257   java
10 谁能帮助我找到MoViNets代码