find the nth root of a number in python

To find the nth root of a number in Python, you can use the ** operator and the math.pow() function. Here's an example of finding the 3rd root of the number 27:

main.py
import math

num = 27
n = 3
result = math.pow(num, 1/n)

print(result) # Output: 3.0
85 chars
8 lines

In the code above, we import the math module to use the pow() function. We define the number we want to find the root of, num, and the root we want to find, n. We calculate the result using the pow() function and print it to the console.

gistlibby LogSnag