Back

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

Why does Python give the "wrong" answer?

x = 16

sqrt = x**(.5)  #returns 4
sqrt = x**(1/2) #returns 1

1 Answer

0 votes
by (8.7k points)

you can start by primarily import math module of python  and using the sqrt function .

But for the above code sqrt=x**(½) simply perform what we called integer division 

First it calculate x(½) and then x(0) ==1

So the answer of this kind equation will always be 0,no matter whatever be the value of x.

So the recommended way is to go with sqrt=X**(.5)

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...