方法一:无脑字符串呗

while 1:
try:
s=input()
num=s[2:]
dic={'A':10,'B':11,'C':12,'D':13,'E':14,'F':15}
res=0
for i in range(len(num)):
if num[i] in dic:
res+=dic[num[i]](16**(len(num)-1-i))
else:
res+=int(num[i])
(16**(len(num)-1-i))
print(res)
except:
break

方法2:调用函数偷懒法。btw:机试能调用函数吗?那逆波兰四则运算以及这道进制转换不就一个函数的事嘛

while True:
try:
print( int(input(), 16) )
except:
break