Question: (a) [4] Decide for each of the following Python functions, if it is pure, and whether it has side-effect: def f1(x): y = 2 return
![(a) [4] Decide for each of the following Python functions, if](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f544690ecfe_86466f544686f70f.jpg)
(a) [4] Decide for each of the following Python functions, if it is pure, and whether it has side-effect: def f1(x): y = 2 return x + y y = 2 def f2(x): return x + y (b) [4] In HW7, you wrote a Python function twice(f) which takes a function f and returns a function that applies f twice to its argument, i.e. twice(f)(x) = f(f(x)) We assume that this function is available. Now implement a Python function quard(f) which takes a function fand returns a function that applies f four times to its argument, i.e. quard(f)(x) = f(f(f(f(x)))) You are required to use twice to implement this function. (Alternative implementation will earn 2 points.) (c) [4] Implement a similar function fivepeat(f) which takes a function f and returns a function that applies f five times to its argument, i.e. fivepeat(f)(x) = f(f(f(f(f(x))))) You are required to use either twice or quard to implement this function. (Alternative implementation will earn 2 points.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
