- def color(c):
- try:
- if c[0]=='#':
- dict1={'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}
- R=dict1[c[1].upper()]*16+dict1[c[2].upper()]
- G=dict1[c[3].upper()]*16+dict1[c[4].upper()]
- B=dict1[c[5].upper()]*16+dict1[c[2].upper()]
- return (R,G,B)
- elif len(c)==3:
- list1=['0','1','2','3','4','5','6','7',\
- '8','9','A','B','C','D','E','F']
- R=list1[c[0]//16]+list1[c[0]%16]
- G=list1[c[1]//16]+list1[c[1]%16]
- B=list1[c[2]//16]+list1[c[2]%16]
- return '#'+R+G+B
- else:return '输入有误'
- except:
- return '输入有误'
复制代码 |