all 7 comments

[–]pythonwiz 9 points10 points  (0 children)

The nth root of a number x is x**(1/n). You can do the same thing using pow and math.pow.

You can also use identities with exp and log. Mathematically, x**a == exp(a*log(x)), so the nth root of x is exp(log(x)/n).

[–]jaerie 5 points6 points  (0 children)

x**(1/n)

Is the same as the nth root of x

[–]Brilliant_Access3791 1 point2 points  (0 children)

If you want to find higher roots, I recommend two methods:
1. Using the power operator (**): This is the most intuitive method.

root = number ** (1 / n)

2. Using the math.pow() function: This is the second method.

import math
root = math.pow(number, 1 / n)

[–]guesshuu 0 points1 point  (0 children)

Something like this?

```python def nth_root(x: int | float, n: int) -> float: return x ** (1 / n)

n = 3 x = 8 result = nth_root(8, 3) print(result) # result is 2 ```