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
;
(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
What are the characteristics of Dictionary?
What are the issues associated with disability while teaching and using computers?
Meera wants to buy a desktop/laptop. She wants to use multitasking computer for her freelancing work which involves typing and for watching movies. Her brother will also use this computer for playing/creating games.
(i) Which of the following hardware has a suitable size to support this feature? Specify the reason.
- ROM
- RAM
- Storage
- All of these
(ii) Meera also wants to use this computer while traveling. What should her preference be — desktop or laptop?
(iii) If Meera has to run Python on her laptop, what should be the minimum RAM required to run the same?
(iv) What is the difference between RAM and storage? Do we need both in a computer?
Draw the structure of the components of a computer and briefly explain the following.
(a) Input Unit
(b) Output Unit
(c) Central Processing Unit
(d) Primary Memory
(e) Secondary Memory