< Back

Post Lab 9

Post labs are to be done individually. Sharing files between students is not allowed. Doing so is an Academic Integrity violation, and will be treated as such.


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

Submissions for post labs are to be done via the inquire system. Go to http://inquire.roanoke.edu/ You should see a section for post labs. Submit your .py file to the appropriate post lab location.

Post labs are to be done individually. Sharing files between students is not allowed. Doing so is an Academic Integrity violation, and will be treated as such.