Skip to content

Functions · warm-up

Clamp

Write clamp(x, low, high): return low if x is below it, high if x is above it, and x otherwise.

Run adds print(clamp(42, 0, 10)) after your code, to try it.

Stuck on the idea rather than the code? The Functions lesson walks through it.