** Consider the following program for the next two questions. 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)  **

 

Q. When this program is run, the following output is generated (note that input entered by the user is shown in bold):

 

Enter the length of the first side: 3

Enter the length of the second side: 4

Traceback (most recent call last):

h = sqrt(a * a + b * b)

NameError: name 'sqrt' is not defined

 

Why is this error occurring? How would you resolve it?

 

Answer =

 

Because sqrt() function of math module. But in this program math module is not import that’s why this give an error.

 

If we import math module then it will give no error.

3 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post