Write a Python function that takes an Integer number, N (num of triangles), and string which contains the base and height of N triangles separated by spaces as arguments. Then it will determine the largest triangle and print its area inside the function. The largest triangle is determined based on the largest area. For calculating the area of a Triangle, you only need its base and height. The formula for calculating the area of a triangle = (½) * base * height. ====================================================== function call 1: function_name(4, "15 5 6 3 6 10 15 2") Sample Input 1: 4 15 5 6 3 6 10 15 2 Sample Output 1: Number of triangles: 4 The area of the largest triangle is 37.5 with a base of 15 and a height of 5 Explanation 1: Here, 4 is the number of triangles and the string contains the base and height of 4 triangles respectively. The area of the first triangle is, therefore (½)*15*5 = 37.5, the next one is (½)*6*3 = 9, the third one is (½)*6*10 = 30 and the last one (½)*15*2 = 15. Finally, the largest triangle is determined based on the largest area which is 37.5 and the output as shown is printed. ====================================================== function call 2: function_name(3, "20 3 33 7 11 14") Sample Input 1: 3 20 3 33 7 11 14 Sample Output 2: Number of triangles 3 The area of the largest triangle is 115.5 with a base of 33 and a height of 7 Explanation 2: Here, 3 is the number of triangles and the string contains the base and height of 3 triangles respectively. The area of the first triangle is, therefore (½)*20*3 = 30, the second one is (½)*33*7 = 115.5 and the third one is (½)*11*14 = 77. Finally, the largest triangle is determined based on the largest area which is 115.5 and the above output is printed.
Write a Python function that takes an Integer number, N (num of triangles),
and string which contains the base and height of N triangles separated by
spaces as arguments. Then it will determine the largest triangle and print
its area inside the function. The largest triangle is determined based on
the largest area.
For calculating the area of a Triangle, you only need its base and height.
The formula for calculating the area of a triangle = (½) * base * height.
======================================================
function call 1:
function_name(4, "15 5 6 3 6 10 15 2")
Sample Input 1:
4
15 5 6 3 6 10 15 2
Sample Output 1:
Number of triangles: 4
The area of the largest triangle is 37.5 with a base of 15 and a height of 5
Explanation 1:
Here, 4 is the number of triangles and the string contains the base and
height of 4 triangles respectively. The area of the first triangle is,
therefore (½)*15*5 = 37.5, the next one is (½)*6*3 = 9, the third one is
(½)*6*10 = 30 and the last one (½)*15*2 = 15. Finally, the largest triangle
is determined based on the largest area which is 37.5 and the output as
shown is printed.
======================================================
function call 2:
function_name(3, "20 3 33 7 11 14")
Sample Input 1:
3
20 3 33 7 11 14
Sample Output 2:
Number of triangles 3
The area of the largest triangle is 115.5 with a base of 33 and a height of
7
Explanation 2:
Here, 3 is the number of triangles and the string contains the base and
height of 3 triangles respectively. The area of the first triangle is,
therefore (½)*20*3 = 30, the second one is (½)*33*7 = 115.5 and the third
one is (½)*11*14 = 77. Finally, the largest triangle is determined based on
the largest area which is 115.5 and the above output is printed.
Step by step
Solved in 2 steps with 1 images