How to take the cube root of a number in python using exponentiation ? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 13

How to take the cube root of a number in python using exponentiation ?

I want to make a calculator code which has the option of cube root. I know how to take the square root of a number. but what about cube roots ? any help would be appreciated. thank you!

11th Aug 2019, 2:12 PM
sujay simha
sujay simha - avatar
20 Respuestas
+ 10
Just use the inverse of the power raised. N**(1.0/3.0) note, this only works for positive values of N.
11th Aug 2019, 2:22 PM
Robert Atkins
Robert Atkins - avatar
+ 17
You can use pow(x, y) x - the number whose root you want to find y - the degree to which to raise the number If y = 1/3 then you get the cubic root pow(27,1/3)
11th Aug 2019, 2:20 PM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
11th Aug 2019, 2:25 PM
sujay simha
sujay simha - avatar
12th Aug 2019, 4:41 AM
sujay simha
sujay simha - avatar
12th Aug 2019, 4:44 AM
sujay simha
sujay simha - avatar
+ 9
Newton-Raphson only needs 8 iterations for sqrt(27) (even when you start with a very poor initial estimate at 1): c = 0 n = 27 y = 1 while abs(y**3 - n) > 0.00001: y = y - (y**3-n)/(3*y**2) c+= 1 print("iterations: ", c) print(round(y))
12th Aug 2019, 2:58 PM
Thoq!
Thoq! - avatar
+ 9
thank you so much Thoq!
13th Aug 2019, 4:37 AM
sujay simha
sujay simha - avatar
+ 9
I will do that Thoq! and thanks a lot for recommending
13th Aug 2019, 5:25 PM
sujay simha
sujay simha - avatar
11th Aug 2019, 4:31 PM
sujay simha
sujay simha - avatar
+ 8
thank you so much Egbeola Samuel
12th Aug 2019, 4:40 AM
sujay simha
sujay simha - avatar
+ 8
Thoq!, i just wanted to know the different methods of getting cube roots. check out this code and please tell me if i can add anything else https://code.sololearn.com/cQ2Wc082SeBM/?ref=app
13th Aug 2019, 7:10 AM
sujay simha
sujay simha - avatar
+ 4
sujay simha I know that this is not really what you were looking for. But I still found it might be interesting to show how a (simple) implementation for finding a root might look like.
13th Aug 2019, 6:53 AM
Thoq!
Thoq! - avatar
+ 4
sujay simha When taking a look at my calculator, I can see a lot of stuff like sine, cosine, log, tan, mean... which you could also implement.
13th Aug 2019, 9:23 AM
Thoq!
Thoq! - avatar
+ 3
like this 4***3
11th Aug 2019, 3:20 PM
Utkarsh Pratap Maurya
Utkarsh Pratap Maurya - avatar
+ 3
pow(a,b) b=1/3 while a= The number you want to find the cube root of
11th Aug 2019, 7:42 PM
Samuel Egbeola
Samuel Egbeola - avatar
+ 3
You are always welcome with more problems
12th Aug 2019, 4:42 AM
Ankit Raghuvanshi
Ankit Raghuvanshi - avatar
+ 2
Import math as m a, b=int(input("enter a number ")), int(input("enter power")) s=m.pow(a, b) print(s)
11th Aug 2019, 8:30 PM
Ankit Raghuvanshi
Ankit Raghuvanshi - avatar
+ 1
pow(num, 1/3)
11th Aug 2019, 9:47 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
+ 1
thnx
18th Aug 2019, 9:41 AM
Mikhail Piksaev
Mikhail Piksaev - avatar
0
This has solved a lot of my problems
31st Jan 2021, 2:49 PM
Quadri Lasisi
Quadri Lasisi - avatar