def tohex(r, g, b):
#your code here :)
def hex1(decimal):
if decimal < 0:
return '00'
elif decimal > 255:
return 'FF'
elif decimal < 17:
return '0'+ hex(decimal)[2:]
else:
return inthex(decimal)[2:]
return (hex1(r) + hex1(g) + hex1(b)).upper()
print rgb(16 ,159 ,-137)
I define a new method to get my hex numbers. But when it comes to (16 ,159 ,-137), I got 0109F00
instead of 019F00
. Why there is an extra 0?