Issue
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.
Solution
sqrt=x**(1/2)
is doing integer division. 1/2 == 0
.
So 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.
Answered By - smessing
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.