This is my take on the cube root challenge - it's performing well, but the main flow is sort of ugly. Suggestions are welcome! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

This is my take on the cube root challenge - it's performing well, but the main flow is sort of ugly. Suggestions are welcome!

https://code.sololearn.com/c4YLvH46fe3W/?ref=app

18th May 2018, 9:42 AM
Johannes
Johannes - avatar
10 Answers
+ 1
Look on this code : def root3(n): l=1 while l**3<n: l*=10 l,k = l/10,l/100 while abs(n-l**3)>0.0001: while l**3<n: l+=k l-=k k/=10 return(round(l,4)) The first while loop corresponds to your ranger function. The second while loop corresponds to the calls of your subtractor function. The third while loop corresponds to your subtractor function. Your ranger function can be optimized, since it search with single steps.
19th May 2018, 2:57 AM
lemmi
lemmi - avatar
+ 2
It‘s not really similar to the newton method as far as I can tell. I wrote an example implementation for you: https://code.sololearn.com/cvsr1hdEoi11/?ref=app
18th May 2018, 1:51 PM
Max
Max - avatar
+ 1
Try Newton’s method
18th May 2018, 9:45 AM
Max
Max - avatar
+ 1
just do: x**(1/3) where x is the number you want the cube root of.
18th May 2018, 10:36 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
Max - i thought my method was very similar to Newtons, no?
18th May 2018, 1:06 PM
Johannes
Johannes - avatar
+ 1
Ulisses Cruz - thanks, but that's too boring :) 😂
18th May 2018, 1:07 PM
Johannes
Johannes - avatar
+ 1
Max - thank you very much. Great code!
18th May 2018, 4:11 PM
Johannes
Johannes - avatar
0
lemmi - thanks for the input! Great explanation
19th May 2018, 8:02 AM
Johannes
Johannes - avatar
0
hi
4th Jun 2018, 9:27 PM
Sadie Gaffer
Sadie Gaffer - avatar
0
nice day
4th Jun 2018, 9:27 PM
Sadie Gaffer
Sadie Gaffer - avatar