Python 37 Code Meet Requirements Please Help Medef Integrate F N Isinstance N Int N 0 Def Q43875752
python 3.7 my code is not meet all requirements, please help medef integrate(f, n): if isinstance(n, int) and n > 0: def f_int(a, b): if a > b: raise AssertionError(‘a should not be greater than b’) else: dx = (b – a) / n integral = 0 while a <= b: integral = integral + f(a) * dx a = a + dx return integral return f_int else: raise AssertionError(‘n should be a positive integer’)2. (5 pts) Define the integrate function, which takes two arguments: (1) a function call it f- (it is univariate: called with one numeric argument and returning a numeric result) and (2) an int value-call it n; if n is not an integer strictly greater than 0, raise an AssertionError exception (with an appropriate error message). The integrate function returns another function that takes two float arguments -call them a and b; if a is not less than or equal to b, raise an AssertionError exception (with an appropriate error message). When the returned function is called, it returns an approximation to the definite integral Sof(x)dx. We approximate this integral by adding up the area of a sequence of n rectangles, whose widths are all (b-a)/n (call this number dx, illustrated below) and whose heights are n values of f starting at f(a) and ending at f(a+ (n-1) dx). If we define int_f = integrate (f,5), Here is how to compute int_f(a,b). f(a+4dx) f(a+3dx) f(a) f(a+dx) f(a+2dx) For the fifth/last point, determine how integrate’s function object can store an attribute named zcc (zero- crossing count) that computes the number of times f’s value crosses 0: from negative (< 0) to positive (20) or from positive to negative: For the picture, after calling int_f(a,b) the int_f.zcc attribute is 0. Hint: function objects can store attributes; there is a relatively simple Boolean/relational expression computing whether two values have opposite signs. Show transcribed image text 2. (5 pts) Define the integrate function, which takes two arguments: (1) a function call it f- (it is univariate: called with one numeric argument and returning a numeric result) and (2) an int value-call it n; if n is not an integer strictly greater than 0, raise an AssertionError exception (with an appropriate error message). The integrate function returns another function that takes two float arguments -call them a and b; if a is not less than or equal to b, raise an AssertionError exception (with an appropriate error message). When the returned function is called, it returns an approximation to the definite integral Sof(x)dx. We approximate this integral by adding up the area of a sequence of n rectangles, whose widths are all (b-a)/n (call this number dx, illustrated below) and whose heights are n values of f starting at f(a) and ending at f(a+ (n-1) dx). If we define int_f = integrate (f,5), Here is how to compute int_f(a,b). f(a+4dx) f(a+3dx) f(a) f(a+dx) f(a+2dx) For the fifth/last point, determine how integrate’s function object can store an attribute named zcc (zero- crossing count) that computes the number of times f’s value crosses 0: from negative (
Expert Answer
Answer to python 3.7 my code is not meet all requirements, please help me def integrate(f, n): if isinstance(n, int) and n > 0: de…
OR