Python Program - Cube Root of a Number
If a number is multiplied by itself two times (n*n*n), the final number will be the cube of that number and finding 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:
Alternatively, it can also be expressed as:
x3 = y
Method 1: Using exponential (**) operator
The exponential (**) operator of Python can be used to calculate the cube root of a number. Consider the following example.
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)
The above code will give the following output:
Cube root of 64 is 3.9999999999999996 Cube root of 125 is 4.999999999999999
Method 2: 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)
The above code will give the following output:
Cube root of 64 is 3.9999999999999996 Cube root of 125 is 4.999999999999999
Recommended Pages
- Python Program - To Check Prime Number
- Python Program - Bubble Sort
- Python Program - Selection Sort
- Python Program - Maximum Subarray Sum
- Python Program - Reverse digits of a given Integer
- Python - Swap two numbers
- Python Program - Fibonacci Sequence
- Python Program - Insertion Sort
- Python Program - Find Factorial of a Number
- Python Program - Find HCF of Two Numbers
- Python Program - To Check Whether a Number is Palindrome or Not
- Python Program - To Check Whether a String is Palindrome or Not
- Python Program - Heap Sort
- Python Program - Quick Sort
- Python - Swap Two Numbers without using Temporary Variable
- Python Program - To Check Armstrong Number
- Python Program - Counting Sort
- Python Program - Radix Sort
- Python Program - Find Largest Number among Three Numbers
- Python Program - Print Floyd's Triangle