Here is a short Python solution,
def rgb(r, g, b): return ('{:02x}'*3).format(*map(lambda x : max(0, min(255, x)), (r, g, b))).upper()
Output,
print(rgb(255, 255, 300)) # output -> FFFFFF print(rgb(0,0,0)) # output -> 000000 print(rgb(148, 0, 211)) # output -> 9400D3 print(rgb(-20,275,125)) # output -> 00FF7D print(rgb(255, 255, 255)) # output -> FFFFFF
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is a short Python solution,
Output,