CBSE Class 11 Computer Science Question 19 of 48

Python Programming Fundamentals — Question 19

Back to all questions
19
Question

Question 14

Write a function called calculate_area() that takes base and height as an input argument and returns an area of a triangle as an output. The formula used is:

Area of a Triangle = ½*base*height

Solution
def calculate_area(base, height):
    area = (1/2) * base * height
    return area

base_value = int(input("Enter the base value: "))
height_value = int(input("Enter the height value: "))
triangle_area = calculate_area(base_value, height_value)
print("Area of the triangle:", triangle_area)
Output
Enter the base value: 10
Enter the height value: 5
Area of the triangle: 25.0
Answer

def
calculate_area
(
base
,
height
):
area
=
(
1
/
2
)
*
base
*
height
return
area
base_value
=
int
(
input
(
"Enter the base value: "
))
height_value
=
int
(
input
(
"Enter the height value: "
))
triangle_area
=
calculate_area
(
base_value
,
height_value
)
print
(
"Area of the triangle:"
,
triangle_area
)
Output
Enter the base value: 10
Enter the height value: 5
Area of the triangle: 25.0