x = 25 epsilon = 0.01 step = 0.1 guess = 0.0 while abs(guess**2-x) >= epsilon: if guess <= x: guess += step else: break if abs(guess**2 - x) >= epsilon: print('failed') else: print('succeeded: ' + str(guess)) ''' iteration = 0 while iteration < 5: count = 0 for letter in "hello, world": count += 1 print("Iteration " + str(iteration) + "; count is: " + str(count)) iteration += 1 iteration = 0 count = 0 while iteration < 5: for letter in "hello, world": count += 1 print("Iteration " + str(iteration) + "; count is: " + str(count)) iteration += 1 ''' ''' cube = 27 epsilon = 0.001 num_guesses = 0 low = 0 high = cube guess = (high + low)/2.0 while abs(guess**3 - cube) >= epsilon: if guess**3 < cube : low = guess else: high = guess guess = (high + low)/2.0 num_guesses += 1 print('num_guesses =', num_guesses) print(guess, 'is close to the cube root of', cube) cube = 27 epsilon = 0.01 guess = 0.0 increment = 0.0001 num_guesses = 0 while abs(guess**3 - cube) >= epsilon: guess += increment num_guesses += 1 print('num_guesses =', num_guesses) if abs(guess**3 - cube) >= epsilon: print('Failed on cube root of', cube) else: print(guess, 'is close to the cube root of', cube) cube = 27 epsilon = 0.05 guess = 0.0 increment = 0.001 num_guesses = 0 while abs(guess**3 - cube) >= epsilon and guess <= cube: guess += increment num_guesses += 1 print('num_guesses =', num_guesses) if abs(guess**3 - cube) >= epsilon: print('Failed on cube root of', cube) else: print(guess, 'is close to the cube root of', cube)'''