Skip to content

Instantly share code, notes, and snippets.

@oca159
Created June 28, 2018 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oca159/4b9cf31f751593843b4bbcb83ecf84d8 to your computer and use it in GitHub Desktop.
Save oca159/4b9cf31f751593843b4bbcb83ecf84d8 to your computer and use it in GitHub Desktop.
'''
The rgb() method is incomplete.
Complete the method so that passing in RGB decimal values will result in a hexadecimal representation being returned.
The valid decimal values for RGB are 0 - 255. Any (r,g,b) argument values that fall out of that range should be rounded to the closest valid value.
'''
def rgb(r, g, b):
round = lambda x: min(255, max(x, 0))
return ("{:02X}" * 3).format(round(r), round(g), round(b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment