2
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)
我定義了一個獲取我的十六進制數的新方法。但是說到(16,159,-137),我得到了0109F00
而不是019F00
。爲什麼有一個額外的0?如何將小數點轉成十六進制,前綴爲0x'
的可能的複製[?如何在Python中使用十六進制()不0X] (https://stackoverflow.com/questions/16414559/how-to-use-hex-without-0x-in-python) –