CSCA08H3 Lecture : Worksheet
Document Summary
Defining a function in python f(x) = x2 f(3) = ______ f(5) = ______ Function definition def double(num): return num + num. Example: function with local variables (func_localvars. py) def polynomial(a, b, c, x): first = a * x * x second = b * x third = c return first + second + third. Consider the following function definition: def strange (x, y): z = 4 z = z + x - y return z + 2. Question: translate this function into python: g(x) = x + 5. What does this program do? def f(x): return x + 3 y = 9 y = f(2) print y. What do the following evaluate to? g(1) g(-4. 2) g(g(5)) f(g(4)) Inside-out rule: apply g, then apply f to the result. Practise: write a function that figures out the total amount of red in a picture.