Welcome to Westonci.ca, where you can find answers to all your questions from a community of experienced professionals. Discover precise answers to your questions from a wide range of experts on our user-friendly Q&A platform. Get quick and reliable solutions to your questions from a community of experienced experts on our platform.

The following function is supposed to return -1 when x is negative, +1 when x is positive, or if x is zero. What, if anything, is wrong with the function? def plusMinusZero(x): if x == 0 : return 0 elif x <= 0 : return -1 else x >= 0 : return 1 A. A return statement must be added at the end of the function B. Both occurrences of elif must be replaced with if C. The <= and >= must be replaced with < and > D. Nothing is wrong with the function

Sagot :

def dx(fn, x, delta=0.001):

   return (fn(x+delta) - fn(x))/delta

def solve(fn, value, x=0.5, maxtries=1000, maxerr=0.00001):

   for tries in xrange(maxtries):

       err = fn(x) - value

       if abs(err) < maxerr:

           return x

       slope = dx(fn, x)

       x -= err/slope

   raise ValueError('no solution found')