KnowledgeBoat Logo

Computer Science

Observe the code given below and answer the following questions. A triangle has three sides — a, b and c, and the values are 17, 23 and 30, respectively. Calculate and display its area using Heron's formula as

S=a+b+c2S =\dfrac{a+b+c}{2} ; Area=S(Sa)(Sb)(Sc)Area = \sqrt{S(S - a)(S - b)(S - c)}

(a) Import the module — Statement 1

(b) Calculate s (half of the triangle perimeter) — Statement 2

(c) Insert function to calculate area — Statement 3

(d) Display the area of triangle — Statement 4

import ...............                          #Statement 1
a, b, c = 17, 23, 30
s = ...............                             #Statement 2
area = ............... (s*(s—a)*(s—b)*(s—c))    #Statement 3
print("Sides of triangle:", a, b, c)
print(...............)                         #Statement 4

Python Modules

2 Likes

Answer

(a) Statement 1: import math is used to access mathematical functions, specifically math.sqrt() for calculating the square root.

(b) Statement 2: s = (a + b + c) / 2 calculates the semi-perimeter of the triangle.

(c) Statement 3: area = math.sqrt(s * (s - a) * (s - b) * (s - c)) uses Heron's formula to compute the area of the triangle.

(d) Statement 4: print("Area of triangle:", area) prints the calculated area.

Answered By

2 Likes


Related Questions