Python Program - Cube Root of a Number


Advertisements

If a number is multiplied by itself two times ($$n*n*n$$), the final number will be the cube of that number and inding the cube root of a number is inverse operation of cubing the number. If x is the cube root of y, it can be expressed as below:

$$x = \sqrt[3]{y}$$

Alternatively, it can also be expressed as:

$$x^3 = y$$

Example: Using exponential (**) operator

The exponential (**) operator of Python can be used to calculate the cube root of a number. Please see the below example for syntax.

x = 64
y = 125
x1 = x**(1/3)
y1 = y**(1/3)
print("Cube root of", x, "is",x1)
print("Cube root of", y, "is",y1)

Output

Cube root of 64 is 4.0
Cube root of 125 is 5.0

Example: Using pow() method of math Module

The pow() method of math module can also be used to calculate cube root of a number.

import math

x = 64
y = 125
x1 = math.pow(x, 1/3)
y1 = math.pow(y, 1/3)
print("Cube root of", x, "is",x1)
print("Cube root of", y, "is",y1)

Output

Cube root of 16 is 4.0
Cube root of 25 is 5.0

Advertisements