Question
Python qns Create a class named Triangle. The class has five instance variables a, b, c, circ, and valid. a, b, c are the side
Python qns
Create a class named Triangle. The class has five instance variables a, b, c, circ, and valid. a, b, c are the side lengths, circ is the circumference of the triangle, valid is True if the three sides can form a triangle; otherwise, it is False. This class Triangle has the following methods:
1. init () Initialize instance variables a, b, c to the inputs when an object is created (i.e., this constructor will take input parameters, and initialize a, b and c as those inputs).
2. is valid() This method sets the instance variable valid to False if the length of any one side is larger than or equal to the sum of the lengths of another two sides; otherwise, this method set the instance variable valie to True.
3. computeCirc() This method compute the circumference of the triangle, then update the instance variable circ.
4. printTriangle() It prints all the instance variables of Triangle to the screen. After creating the Triangle class, create an object tri1 of Triangle with three input parameters (2.1, 3.4, 5.2).
After creating the object tri1, call tri1.is valid(), and followed by tri1.computeCirc(). Then call the method tri1.printTriangle to print all the instance variables to the screen.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started