Forum Archive

math.pow() problem

misha_turnbull

I have a question with the math.pow() function. I was attempting to take the nth root of a number, and there is no function to take roots other than 'sqrt()'. So I tried to use fractional exponents, since 4^(1/2) is the same as taking the square root of 4. I tested this theory in the interpreter, but this is what happened:

>>>pow(2, (1/2))

1.0

>>>pow(4, (1/2))

1.0

As you can see, the app is telling me that 2^(1/2) and 4^(1/2) are both equal to 1, which is true of neither. My question is, how do I take nth roots of a number?
Thank you!

*sorry for the bad formatting, Im new at this

misha_turnbull

Ohh darn this is in the wrong place. I just saw the 'Pythonista' category underneath 'Editorial'....anyone know how to move posts?

omz

The problem is that 1/2 evaluates to 0 because you're dividing two integers, if you use 1.0/2.0 instead, you should get the expected result (1./2 is actually enough).