easy +10 pts

Clamp and round to nearest ten

Clamp a number to a range, then round to the nearest ten with halves away from zero.

Write a function `clamp_round_to_ten(value, low, high)` that takes a number `value` and two numbers `low` and `high`, where `low <= high`. First, clamp `value` to the inclusive interval `[low, high]`: if `value` is below `low`, set it to `low`; if above `high`, set it to `high`; otherwise keep it unchanged. Then round the clamped value to the nearest multiple of 10 using the rule that halves round away from zero (e.g., 15 rounds to 20, -15 rounds to -20, 5 rounds to 10, -5 rounds to -10). Return the resulting integer.

Constraints

Inputs can be integers or floats. `low <= high` always holds. Assume `low` and `high` are finite numbers (integers or floats). The result must be an integer.

Example

>>> clamp_round_to_ten(13, 0, 100)
10
>>> clamp_round_to_ten(27, 10, 20)
20
>>> clamp_round_to_ten(-8, -30, -5)
-10
>>> clamp_round_to_ten(5, 10, 20)
10
>>> clamp_round_to_ten(18, 12, 15)
20
10 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Clamp first, then round.
Use the formula that rounds halves away from zero: for positive numbers use int(x + 5) // 10 * 10, for negative numbers use -((int(-x) + 5) // 10 * 10).
Be careful with negative values: -15 should become -20, not -10.
Use a helper function or inline expression for rounding.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.