Triangle Area
You are asked to write a Python function
triangle_area(a, b, c)
that calculates the area of a triangle given its three sides: a
, b
, and c
. The function should take three positional-only arguments and return the calculated area as a floating-point number.The area of the triangle can be calculated using Heron's formula:
The function should take into account that the triangle inequality theorem (in any triangle, the sum of the lengths of any two sides must be greater than or equal to the length of the remaining side) should be satisfied for
a
, b
, and c
, or else, the function should return a suitable error message: Invalid triangle
.The function should not have any standard or keyword arguments, only positional ones.
The inputs to the function are three floating-point numbers:
a
, b
, and c
- the lengths of the sides of the triangle.The function should return a single floating-point number representing the calculated area, or a string with an error message.
Input | Output |
3 4 5 | 6.0 |
1 10 12 | Invalid triangle |
Note: Degenerate triangles (where the area is 0) are also considered valid. So, the output of the program in that case should be 0.
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB