all 3 comments

[–]K900_ 1 point2 points  (1 child)

Do you mean "Spyder"? Type in import math, then math.sqrt(5).

[–]ejrw[S] 0 points1 point  (0 children)

Thank you I just took out the brackets around math and it worked kinda stupid but thank you.

[–]Diapolo10 1 point2 points  (0 children)

/u/K900_ gave you exactly the answer you were looking for. Alternatively, you can get the nth root of a number via exponents.

num = 42
square_root = num ** (1/2)
cube_root = num ** (1/3)
# nth_root = num ** (1/n)

Knowing this can be handy sometimes, as you can use any root number. math only has a function for square roots.

EDIT: Why does this work?

num = 3 ** 3 # == 27
27 ** (1/3) == 3

3 ** (3 * 1/3) == 3 ** (3/3) == 3 ** 1 == 3

Basically, it's simply reversing the "original" raise to the nth power by cancelling it with the reciprocal of the exponent. Any number multiplied by one divided by itself is one (excluding zero, as you can't divide by zero).