Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My question is python 2.7. I\'ve done the top but cannot figure out the rest. He

ID: 3786750 • Letter: M

Question

My question is python 2.7. I've done the top but cannot figure out the rest. Here is the code.

from __future__ import division
import math

def close_enough(x, y, error = 0.0000001):
    return abs(x - y) < error

def search_for_midpoint(f, neg_point, pos_point):
    midpoint = (neg_point + pos_point)/2
    if close_enough(neg_point, pos_point):
        return midpoint
    else:
        ## NEED CODE HERE

def half_interval_method(f, a, b):
    a_val = f(a)
    b_val = f(b)
    if a_val < 0 and b_val > 0:
        return search_for_midpoint(f, a, b)
    elif b_val < 0 and a_val > 0:
        return search_for_midpoint(f, b, a)
    else:
        raise Exception('Values are not of oppositive sign')

def fixed_point(f, guess, error=0.0000000000001):
    prev_guess = guess
    curr_guess = f(prev_guess)
    num_iters = 0
    while not close_enough(prev_guess, curr_guess, error=error):
        ##NEED CODE HERE
    return (num_iters, curr_guess)

"NEED CODE HERE" is what I need it.

Explanation / Answer

By seeing the code i have made changes. is this what you are looking for?

Ask anything if you have any doubt.

from __future__ import division
import math
def close_enough(x, y, error = 0.0000001):
return abs(x - y) < error

def search_for_midpoint(f, neg_point, pos_point):
midpoint = (neg_point + pos_point)/2
if close_enough(neg_point, pos_point):
return midpoint
else:
raise Exception('no mid point')
  
def half_interval_method(f, a, b):
a_val = f(a)
b_val = f(b)
if a_val < 0 and b_val > 0:
return search_for_midpoint(f, a, b)
elif b_val < 0 and a_val > 0:
return search_for_midpoint(f, b, a)
else:
raise Exception('Values are not of oppositive sign')
  
def fixed_point(f, guess, error=0.0000000000001):
prev_guess = guess
curr_guess = f(prev_guess)
num_iters = 0
while not close_enough(prev_guess, curr_guess, error=error):
curr_guess = f(prev_guess)
num_iters+=1
return (num_iters, curr_guess)