Menu

gitpiper

clamp_number python Code Snippet in 2022

mathbeginner

Last Updated: 25 September 2022

Clamps num within the inclusive range specified by the boundary values.

  • If num falls within the range (a, b), return num.
  • Otherwise, return the nearest number in the range.
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

python snippet similar to clamp_number For You in September 2022

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2022 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️