1 class Solution:
 2     def toHexspeak(self, num: str) -> str:
 3         dic = {'a':'A','b':'B','c':'C','d':'D','e':'E','f':'F','1':'I','0':'O'}
 4         dn_10 = int(num)
 5         dn_16 = hex(dn_10)#10进制转16进制
 6         str_16 = str(dn_16)[2:]#去掉前缀 0x
 7         r = ''
 8         for i in range(len(str_16)):
 9             if str_16[i] in dic:
10                 r += dic[str_16[i]]
11             else:
12                 return 'ERROR'
13         return r

 

posted on 2019-12-01 08:52  Sempron2800+  阅读(151)  评论(0编辑  收藏  举报