subject

Given class Triangle, complete the program to read and set the base and height of triangle1 and triangle2, determine which triangle's area is larger, and output the larger triangle's info, making use of Triangle's relevant methods. Ex: If the input is:
3.0
4.0
4.0
5.0
where 3.0 is triangle1's base, 4.0 is triangle1's height, 4.0 is triangle2's base, and 5.0 is triangle2's height, the output is:
Triangle with larger area:
Base: 4.00
Height: 5.00
Area: 10.00
class Triangle:
def __init__(self):
self. base = 0
self. height = 0
def set_base(self, user_base):
self. base = user_base
def set_height(self, user_height):
self. height = user_height
def get_area(self):
area = 0.5 * self. base * self. height
return area
def print_info(self):
print('Base: {:.2f}'.format(self. base))
print('Height: {:.2f}'.format(self. height))
print('Area: {:.2f}'.format(self. get_area()))
if __name__ == "__main__":
triangle1 = Triangle()
triangle2 = Triangle()
# TODO: Read and set base and height for triangle1 (use set_base() and set_height())
# TODO: Read and set base and height for triangle2 (use set_base() and set_height())
# TODO: Determine larger triangle (use get_area())
print('Triangle with larger area:')
# TODO: Output larger triangle's info (use print_info())

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:00
What are two of the most common reasons that peolpe who need mental health care do not access it?
Answers: 1
question
Computers and Technology, 22.06.2019 12:30
Some of the first computer games were created in the early 1970s by college students experimenting after hours to see what the were capable of doing.
Answers: 3
question
Computers and Technology, 22.06.2019 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 22.06.2019 19:20
Consider the following code snippet: #ifndef cashregister_h#define cashregister_hconst double max_balance = 6000000.0; class cashregister{public: cashregister(); cashregister(double new_balance); void set_balance(double new_balance); double get_balance() const; private: double balance[12]; }; double get_monthly_balance(cashregister bk, int month); #endifwhich of the following is correct? a)the header file is correct as given.b)the definition of max_balance should be removed since header files should not contain constants.c)the definition of cashregister should be removed since header files should not contain class definitions.d)the body of the get_monthly_balance function should be added to the header file.
Answers: 1
You know the right answer?
Given class Triangle, complete the program to read and set the base and height of triangle1 and tria...
Questions
question
Mathematics, 22.10.2020 18:01
question
Mathematics, 22.10.2020 18:01
question
Mathematics, 22.10.2020 18:01
question
Mathematics, 22.10.2020 18:01
question
Chemistry, 22.10.2020 18:01
Questions on the website: 13722363