Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

Consider the Python code:

import numpy as np

print(np.sqrt(1 - 0.5**2))

This returns a long decimal beginning with 0.86, whereas I would expect it to return 0.75. Why the discrepancy?

1 Answer

0 votes
by (25.1k points)

print(np.sqrt(1 - 0.5**2))

This because in python your code is being interpreted in this order.

Firstly 0.5 is raised to 2 so this results in np.sqrt(1 - 0.25), then do a square root of  0.75 so we get 0.86. Which is why you are getting 0.86 and not 0.5.

Related questions

Browse Categories

...