How to extract an arithmetic root of arbitrary degree in Python?
I know that algorithm:
z = pow(x,(1/N))
Is this correct?
Is this the only way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is indeed the way to go. However, you need to use
1.0/Nto ensure float division (unlessNis always a float):You could also use
from __future__ import divisionto make/the “regular” division operator (for integer division you would then use//):Instead of
math.pow(x, y)you could also use thex ** yoperator: