Answered step by step
Verified Expert Solution
Question
1 Approved Answer
DONE USING PYTHON. 1. TASK 1 Write a function fact(n) that calculates the factorial n ! of an input natural number n. 2. TASK 2
DONE USING PYTHON.
1. TASK 1 Write a function fact(n) that calculates the factorial n ! of an input natural number n. 2. TASK 2 Write a function powTwo(x) that calculates 2 to the power of x for any number x 3. TASK 3 Write a decorator called commute which takes as input two functions f and g, and returns the commutator fg - gf. So, when applied to a variable x, commute(f,g)(x) should return f(g(x)) - g(f(x)). 4. TASK 4 Test your decorator by calculating commute(fact,powTwo)(5) commute(powTwo,fact)(6) and report both of these answersStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started