CSCA08H3 Lecture : Worksheet

48 views4 pages
19 Oct 2011
School
Course

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions