Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the cube root in Python?

Tags:

python

I've tried to find the cube root in Python but I have no idea how to find it. There was 1 line of code that worked but he wouldn't give me the full number. Example:

math.pow(64, 1/3)

This doesn't give me 4 tough but 3.99999. Does anyone know how I am supposed to fix this?

like image 379
A. Johnson Avatar asked Mar 21 '18 08:03

A. Johnson


1 Answers

in Python 3.11, math.cbrt

 x = 64
 math.cbrt(x)

(or)

use numpy

import numpy as np
x = 64
np.cbrt(x)
like image 100
SuperNova Avatar answered Oct 14 '22 04:10

SuperNova