Question: Q 3 . ( a ) Write an implementation of the following function for computing an approximation to the derivative of a function. def diff

Q3.(a) Write an implementation of the following function for computing an approximation to the derivative of a function. def diff(f, h): '''Return a function that approximates the derivative of the function 'f'(which is assumed to take one argument of type 'float' and returning a 'float') using the formula f'(x) ~ (f(x+h)- f(x-h))/2h where 'h' is a 'float'.''' # your code here [5 marks](b) Explain what a decorator is in Python, and what the syntax for using a decorator is.[5 marks](c) Give three examples of uses of decorators. [3 marks](d) Write a logging decorator log such that after each call of a function to which the decorator is applied, the parameters and return value are printed as in the following example: def foo(x, y): print("hello!") return abs(x-y) After applying the decorator, when we call the function we would get: >>> foo(12,15) hello! foo(12,15)=3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!