0

I have a number N let's say 5451 and I want to find the base for power 50. How do I do it with python?

The answer is 1.1877622648368 according this website (General Root calculator) But i need to find it with computation.

Second question. If I have the number N 5451, and I know the base 1.1877622648368, how do I find the power?

luky
  • 2,263
  • 3
  • 22
  • 40

1 Answers1

2

Taking the n-th root is the same as raising to the power 1/n. This is very simple to do in Python using the ** operator (exponentiation):

>>> 5451**(1/50)
1.1877622648368031

The second one requires a logarithm, which is the inverse of exponentiation. You want to take the base-1.1877622648368031 logarithm of 5451, which is done with the log function in the math module:

>>> import math
>>> math.log(5451, 1.1877622648368031)
50.00000000000001

As you can see, there's some roundoff error. This is unavoidable when working with limited-precision floating point numbers. Apply the round() function to the result if you know that it must be an integer.

Thomas
  • 174,939
  • 50
  • 355
  • 478
  • ah, i am stupid i am not thinking at all. thanks. yes i know logarithm but my brain is like dead not thinking at all crazy. ok thanks ā€“ luky Feb 21 '21 at 11:43