CBSE Class 11 Computer Science Question 128 of 173

Data Handling — Question 17

Back to all questions
17
Question

Question 13

Consider the following program. It is supposed to compute the hypotenuse of a right triangle after the user enters the lengths of the other two sides.

a = float(input("Enter the length of the first side:"))
b = float(input("Enter the length of the second side:"))
h = sqrt(a * a + b * b)
print("The length of the hypotenuse is", h)

After adding import math to the code given above, what other change(s) are required in the code to make it fully work ?

Answer

After adding import math statement, we need to change the line h = sqrt(a * a + b * b) to h = math.sqrt(a * a + b * b). The corrected working code is below:

import math
a = float(input("Enter the length of the first side:"))
b = float(input("Enter the length of the second side:"))
h = math.sqrt(a * a + b * b)
print("The length of the hypotenuse is", h)
Answer