Created
September 20, 2013 16:40
-
-
Save soedar/6640332 to your computer and use it in GitHub Desktop.
HOP Extra Practice Q7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # For this question, you are suppose to create a poly generator function, that would create | |
| # a *function* that when passed in a value x, calculate the polynomial of using the coefficient | |
| # that was used when the function is created. | |
| # In short, we are given this function has already been defined for us: | |
| def poly(coefficient, x): | |
| # returns the following: | |
| # (coeff[0] * x^0) + (coeff[1] * x^1) + (coeff[2] * x^2) + ... | |
| # and we want to create a function which would create a function that looks like the above, but has fixed | |
| # the coefficient argument of the poly function. | |
| def calculator_generator(coefficient): | |
| # should return a function that looks like poly, but has the coefficient parameter fixed. | |
| ################################################ | |
| # If you are still stuck, consider this example | |
| # that we have done before. | |
| ################################################ | |
| # Assume we have a function: | |
| def multiply(x, y): | |
| return x*y | |
| # Create a function, multipler, such that: | |
| mult2 = multipler(2) | |
| mult2(3) # prints 6 | |
| def multiplier(x): | |
| # what should this function look like? | |
| # How would you solve this problem? | |
| # If you can solve this problem, could you apply the | |
| # same concept to the earlier problem? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment