Square and cube factories
Input
make_power(2)(3)
Output
9
make_power(2) returns a function that squares its input. Calling it with 3 returns 9.
Full lesson preview
Build a function factory that returns specialized functions capturing parameters from their creation scope.
Problem statement
Task
Examples
Input
make_power(2)(3)
Output
9
make_power(2) returns a function that squares its input. Calling it with 3 returns 9.
Input
make_power(0)(5)
Output
1
Any non-zero number to the power 0 is 1.
Input format
Output format
Constraints
Samples
Input
make_power(-1)(2)
Output
0.5
A negative exponent inverts the base (2 ** -1 == 0.5).