• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Python nth Root – Find nth Root of Number with math.pow() Function

Python nth Root – Find nth Root of Number with math.pow() Function

January 29, 2022 Leave a Comment

In Python, the easiest way we can find the nth root of a number is to use the pow() function from the Python math module.

import math

n = 3

cube_root_of_10 = math.pow(10,1/n) #nth root of 10 where n = 3

You can also use the built in ** operator to find the nth root of a number.

n = 5

fifth_root_of_10 = 10**(1/n)

The Python math module has many powerful functions which make performing certain calculations in Python very easy.

One such calculation which is very easy to perform in Python is finding the nth root of a number.

The pow() function from the Python math module also lets us compute roots.

The Python power function pow() takes two numbers as input, the first number is the base and the second number is the exponent. The first number must be positive, but the second number can be negative.

For the nth root of a number, we pass “1/n” to the second parameter in the pow() function.

Below are some examples of how to use the pow() function to find different roots of a number.

For example, if we want to find the square root of a number in Python, we pass “1/2” to the pow() function.

import math

print(math.pow(4, 1/2))
print(math.pow(9, 1/2))
print(math.pow(13, 1/2))
print(math.pow(90, 1/2))
print(math.pow(2182, 1/2))

#Output:
2.0
3.0
3.605551275463989
9.486832980505138
46.71188285650665

For example, if we want to find the square root of a number in Python, we pass “1/3” to the pow() function.

import math

print(math.pow(4, 1/3))
print(math.pow(9, 1/3))
print(math.pow(13, 1/3))
print(math.pow(90, 1/3))
print(math.pow(2182, 1/3))

#Output:
1.5874010519681994
2.080083823051904
2.3513346877207573
4.481404746557164
12.970346612351785

In general, to find the nth root of a number in Python, pass “1/n”. For example, to get the fifth root of a number, we pass “1/5” to the second parameter of pow().

import math

print(math.pow(124, 1/5))

#Output:
2.622311847181126

Finding the nth Root of a Number with the ** Operator in Python

We can also use the built in ** to perform exponentiation in Python. To find a nth root with the ** operator, we just put “(1/n)” after **.

Unlike the pow() function, we can find the nth root of negative numbers with the ** operator if n is odd.

Below are some examples of how to use the Python built in ** operator to find nth roots.

import math

#n=2
print(4**(1/2))

#n=3
print(9**(1/3))

#n=5
print(-13**(1/5))

#n=6
print(90**(1/6))

#n=9
print(-2182**(1/9))

#Output:
2.0
2.080083823051904
-1.6702776523348104
2.1169328630254585
-2.3495455051249885

Hopefully this article has been beneficial for you to learn how to find the nth root of a number in Python.

Other Articles You'll Also Like:

  • 1.  How to Create Array from 1 to n in Python
  • 2.  How to Remove All Occurrences of a Character in a List Using Python
  • 3.  pandas product – Get Product of Series or DataFrame Columns
  • 4.  Count Letters in Word in Python
  • 5.  Truncate String in Python with String Slicing
  • 6.  How to Split List in Half Using Python
  • 7.  Ceiling Division in Python
  • 8.  Python power function – Exponentiate Numbers with math.pow()
  • 9.  Are Dictionaries Mutable in Python? Yes, Dictionaries are Mutable
  • 10.  How to Group By Columns and Find Minimum in pandas DataFrame

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy