def formatter(vals):
def clamp(x):
'''Fixes the values between 0 and 100'''
return max(0, min(100, x))
def string_formatter(x):
'''Formats the values into a string with width 4'''
if x == 100:
return "{:<4g}".format(x)
elif x == 0:
return ' '*4
else:
return "{:>4.1f}".format(x)
return [string_formatter(clamp(i)) for i in vals]