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
        else:
            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)

Put a test print(f(guess)) after guess = 1.0 and see.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.