Question
Objective Create a python program that determines properties of a triangle Specification: Create a python program triangle.py that given the lengths of three sides of
Objective
Create a python program that determines properties of a triangle
Specification: Create a python program triangle.py that given the lengths of three sides of a triangle, your program should provide answers for each of the following questions:
-
Is it really a triangle? If one side is longer than the sum of the other two sides, then it is not.
-
Is it a right triangle? That is, does it satisfy the Pythagorean Theorem? If it is not a triangle, skip this question.
-
What is the perimeter of the triangle?
-
What is the area of the triangle? Usesqrt(s(sa)(sb)(sc)), where
s=1/2*perimeter,a,b,c are the lengths of the three sides.
You need to break up your program into three functions:
classify_triangle([]) # this function will print out the answer of question 1, 2. # Arguments: a list, which contains three numbers, indicates a triangle. # return: None
perimeter([]) # this function will calculate the perimeter of the triangle. # Arguments: a list, which contains three numbers, indicates a triangle. # return: a number(the perimeter)
area([]) # this function will calculate the area of the triangle # Arguments: a list, which contains three numbers, indicates a triangle. # return: a number(the area)
Hints:
You may need following functions :
math.sqrt(), list.sort(). #Here is an example of using list.sort(): a = [3, 2, 1] a.sort() print(a) # [1,2,3] will be printed.
Example test cases:
sides = [2,2,2] classify_triangle(sides) print(The area of the triangle is, area(sides)) print(The perimeter of the triangle is, perimeter(sides))
The above main program should print following sentences:
This is a triangle. This is not right triangle.
The area of the triangle is 1.732.The perimeter of the triangle is 6.0.
------------------------------------------------------------------------------------------------------------------------------- -
sides = [3,4,5] classify_triangle(sides) print(The area of the triangle is, area(sides)) print(The perimeter of the triangle is, perimeter(sides))
The above program should print following sentences:
This is a triangle. This is a right triangle.
The area of the triangle is 6.0. The perimeter of the triangle is 12.0.
------------------------------------------------------------------------------------------------------------------------------- -
sides = [8,5,2] classify_triangle(sides)
The above program should print following sentences:This is not a triangle.
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