Computer Science

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 ?

Python Data Handling

15 Likes

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)

Answered By

10 Likes


Related Questions