DEV Community

Discussion on: Daily Challenge #236 - RGB to Hex Conversion

Collapse
 
maskedman99 profile image
Rohit Prasad

Python

r = int(input("R: "))
g = int(input("G: "))
b = int(input("B: "))

def rgb(var):
        if var < 0:
                var = 0
        if var > 255:
                var = 255

        return hex(var).split('x')[-1].zfill(2)

print('#',rgb(r), rgb(g), rgb(b), sep='')
Collapse
 
pavi2410 profile image
Pavitra Golchha • Edited

You need to create a rgb function which takes three arguments. Also, this challenge didn't specify to put # at the start.