Keep the paddle on screen
Pygame challenges · Bounce, step 2 of 3 · 15 XP
Hold an arrow key and the paddle slides off the screen.
Your task
Write clamp(value, low, high): value, but never below low or above high.
The paddle is 80 wide on a 480 screen, so the game keeps its left edge between 0 and 400 with clamp(paddle_x, 0, 480 - 80). Your bounce from the last step moves the ball.
The function is at the top of the program, marked fix this. Press Run to play the game as it is, then Check when your function is ready.
What Check tests
| Call | Should give |
|---|---|
a value inside staysclamp(50, 0, 100) | 50 |
too low becomes lowclamp(-20, 0, 400) | 0 |
too high becomes highclamp(430, 0, 400) | 400 |
the edges themselves are allowedclamp(400, 0, 400) | 400 |