#510 · Functions · Beginner · 25 XP · about 3 min
Write clamp(value, low=0, high=100) that keeps value inside the range from low to high:
low becomes low,high becomes high,When low and high are left out, the range is 0 to 100, like a volume slider.
clamp(150) # returns 100 clamp(-20) # returns 0 clamp(42) # returns 42 clamp(7, 1, 6) # returns 6 clamp(15, high=10) # returns 10
low is never bigger than high.
First solves only, ranked by stars and then time.