The accumulator pattern appears in a lot of mathematical structures. In this post-lab you will demonstrate your understanding of the accumulator pattern by writing a power function.
Details
Create a function called compute_power(base, exponent)
in a file called power.py. This function should have two
parameters: a floating point value representing the base of the
power and an integer representing the exponent. It should return a
floating point value representing the exponentiation of raising the
base to the specified power. The function should not use
the ** operator.
Recall that exponentiation is simply:
$$ b^n = \underbrace{b \times b \times \ldots \times b \times b}_n$$
Where there are \(n\) occurances of \(b\) in the terms on the right hand side of the equation.
Test your function by calling the function multiple times with different parameters. Make sure you follows the course's code conventions.
Test Cases
Function Parameters | Expected Output |
---|---|
1, 0 | 1 |
1, 1 | 1 |
2, 0 | 1 |
2, 1 | 2 |
2, 2 | 4 |
2, 3 | 8 |
2, 10 | 1024 |
Submission
Submit your program as a .py file on the course Inquire page before class on Friday September 19th.