cs211 lab4
http://www.maths.nuigalway.ie/~gettrick/teach/cs211/labs/l4.html
-
For this lab you must submit all source code (python
files), and, if applicable, the result(s) of running the program on (a few)
test cases. This should be sent in as a file upload/attachment via BLACKBOARD (not directly by email).
The source code must
be well presented (indenting, spaces, reasonable variable/function names,
etc.) and must include comments (as a rough guideline - aim to have nearly as
many comments as lines of code). Any questions asked should be answered by
typing the answers into the relevant box on the BLACKBOARD upload form, or
by including the answer in comments in the PYTHON source code..
-
This material should be uploaded
before
the deadline of 10pm
Thursday November 9th., 2017. You will lose 20% for each day
(or part of day) the lab is late.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated.
You risk getting zero for your lab if it is found to be
plagiarized.
-
TASK 1
Write a function fact(n) that calculates the factorial n!
of an input natural number n.
-
TASK 2
Write a function powTwo(x) that calculates 2 to the power of
x for any number x
-
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)).
-
TASK 4 Test your decorator by calculating
- commute(fact,powTwo)(3)
- commute(powTwo,fact)(4)
and report both of these answers.
©
NUI, Galway