num
within the inclusive range specified by the boundary values.num
falls within the range (a
, b
), return num
.def clamp_number(num, a, b):
return max(min(num, max(a, b)), min(a, b))
clamp_number(2, 3, 5) # 3 clamp_number(1, -1, -5) # -1
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️