-1
x = -37
epsilon = 0.01
num_guess = 0
low = 0.0
high = abs(x)

ans = ((low + high)/2.0)

while abs(ans**3-abs(x)) >= epsilon:
    #print("low = " + str(low) + " high " + str(high) + " ans = " + str(ans))
    if ans**3 < abs(x):
        low = ans
    else :
        high = ans
    ans = ((low + high)/2.0)
    num_guess += 1 

if x < 0:
    ans = -ans
print("Steps taken during bisecction search: ",num_guess)
print("The cube root of " + str(x) + " is " + str(ans))

this is the code sample. I couldn't find a way to find the cube root of floats. Dont know where to insert the command and somehow the site needs more details , so this is why I am writing so much

  • To take a cube root you can use `pow`: `cube_root_of_x = pow(x, 1.0/3)`. – lurker Apr 25 '20 at 12:35
  • 1
    Does this answer your question? [How to find cube root using Python?](https://stackoverflow.com/questions/28014241/how-to-find-cube-root-using-python) – Artyer Apr 25 '20 at 12:37
  • Well, that program is for integers, while my question is how to take the cube root of numbers that are <1 and >0. – Ziya Alim Apr 26 '20 at 16:41

1 Answers1

0

You could simply write the root as a power.

For instance, x ** (1/3) gives you the cubic root of x.

mckbrd
  • 859
  • 9
  • 11
  • but you see this is a challenge given by the OCW's open-course coursewares. instead of defining a function, they suggest that we should make changes in the algorithm. – Ziya Alim Apr 26 '20 at 16:39