Intellipaat Back

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

Why does Python give the "wrong" answer?

x = 16 

sqrt = x**(.5) 

returns 4 

sqrt = x**(1/2) 

returns 1

Yes, I know import math and use sqrt. But I'm looking for an answer to the above.

1 Answer

0 votes
by (106k points)
edited by

Python is giving you the wrong answer because  sqrt=x**(1/2) is doing integer division. 1/2 == 0.

This is the correct answer because you're computing x(1/2) in the first instance, x(0) in the second.

So it's not wrong, it's the right answer to a different question.

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
asked Feb 12, 2021 in Python by adhiraj (4k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...