def hex_to_rgb():
hex = input("Input Hex Color Code. add space after every 2 letter, for example white - FF FF FF:")
hexa = hex.split()
values = {"0" : 0,"1" : 1,"2" : 2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9" : 9, "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15}
rgb_code = []
red_input = str(hexa[0:1])
red_input2 = list(red_input)
red_input3 =[]
for item in red_input2:
if item in values:
red_input3.append(values[item])
decimal = []
red_input4 = sorted(red_input3)
for number in red_input4:
if red_input4.index(number) == 0:
decimal.append(number*1)
if red_input4.index(number) == 1:
decimal.append(number*16)
rgb_red = 0
for redcode in decimal:
rgb_red += redcode
the Code for reference. the code works when I input F5 for example, but when I input FF it breaks, since index()
returns the lowest index for duplicates. is there any way to help this?