题解 | 进制转换
import re convert_dict = {'F':15,'E':14,'D':13,'C':12,'B':11,'A':10} a = input() pattern = re.compile(r"0x(.*)") b = pattern.search(a) c = b.group(1) l = len(c) result = 0 for i in range(l): number = 0 try: number = int(c[i]) except: number = int(convert_dict[c[i]]) result += (16 ** (l-i-1)) * number print(result)