if f(guess)-guess < epsilon:
TypeError: unsupported operand type(s) for -: 'function' and 'float'
This error message is being displayed.
here is my code:

def fixedPoint(f, epsilon):
    f: a function of one argument that returns a float
    epsilon: a small float

    returns the best guess when that guess is less than epsilon 
    away from f(guess) or after 100 trials, whichever comes first.

    guess = 1.0
    for i in range(100):
        if f(guess)-guess < epsilon:
            return guess
            guess = f(guess)
    return guess

def babylon(a):
    def test(x):
        return 0.5 * ((a / x) + x)
    return test

def sqrt(a):
    return fixedPoint(babylon, 0.0001)
5 Years
Discussion Span
Last Post by pyTony

This test question for MITx course should not be discussed before ending of the test period Nov 4. I can just say that you should do the first problem of debugging the fixedPoint before trying to use it in following parts.

Edited by pyTony

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.