CPSC120A
Fundamentals of Computer Science I

Lab 17

Test 2 Review

Practice 1

Write a function sum_powers(n), which computes the sum of the numbers in the set:

$$\{x^{x} \mid 0 < x \leq n\}$$
Which in sigma notation is:
$$ \sum\limits_{x=1}^{n} x^x = 1^1 + 2^2 + 3^3 + \ldots + n^n$$


Practice 2

Write a function called compute_product(n), which computes the series:

\[\prod\limits_{x=2}^{n} \frac{x}{x-1} = \frac{2}{1} \times \frac{3}{2} \times \frac{4}{3} \times \ldots \times \frac{n}{n-1}\]


Practice 3

Write a function called clamp_even(n, minimum, maximum), which returns the value of n "clamped" to the range \([minimum, maximum]\) only if n is even. If n is odd,it should return n. Clamping is a process where values less than the specified minimum get set to the minimum, and values greater than the maximum get set to the maximum. Any value in the range stays the same.


Submission

Please show your source code and run your programs for the instructor or lab assistant. Only a programs that have perfect style and flawless functionality will be accepted as complete.