i am new to python need help Sections 12.2-12.6 12.1 (The Triangle class Design
ID: 3829918 • Letter: I
Question
i am new to python need help
Sections 12.2-12.6 12.1 (The Triangle class Design a class named Triangle that extends the GeometricObject class. The Triangle class contains L Three float data fields named sidel, side2, and side3 to denote the three sides of the triangle. A constructor that creates a triangle with the specified sidel, side2, and side3 with default values 1.0 The accessor methods for all three data fields. L A method named getArea C that returns the area of this triangle L A method named getPerimetero that returns the perimeter of this triangle. L A method named str LO that returns a string description for the triangle. Programming Exercises 429 For the formula to compute the area of a triangle, see Exercise 2.14. The str -O method is implemented as follows return "Triangle sidel str (side 1) side2 str(side2) side3 str (side 3) Draw the UML diagrams for the classes Triangle and Geometricobject. Implement the Triangle class. Write a test program that prompts the user to enter the three sides of the triangle, a color, and 1 or 0 to indicate whether the tri angle is filled. The program should create a Triangle object with these sides and set the color and filled properties using the input. The program should display the triangle's area, perimeter, color, and True or False to indicate whether the trian gle is filled or not.Explanation / Answer
import math
class Triangle:
def __init__(self, side1 = 1.0, side2 = 1.0, side3=1.0):
self.side1=side1
self.side2=side2
self.side3=side3
def getSide1(self):
return self.side1
def getSide2(self):
return self.side2
def getSide3(self):
return self.side3
def getArea(self):
s = self.getPerimeter()/2
area = s*(s-self.side1)*(s-self.side2)*(s-self.side3)
return math.sqrt(area)
def getPerimeter(self):
return self.side1 + self.side2 + self.side3
def __str__(self):
return "Triangle: side1 = " + str(self.side1) + " side2 = " + str(self.side2) + " side3 = " + str(self.side3)
# geometric shape class is required to make few changes here.
# code link: https://paste.ee/p/IxLtf
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.