怎么说呢,这道题挺无语的,看看就行。

import sys
try:
    while True:
        line = sys.stdin.readline().strip()
        if line == '':
            break
        s = 0
        alphabet_base = ord('A')
        num_base = ord('0')
        for val in line.lstrip('0x'):
            if ord(val) >= alphabet_base:
                s = s * 16 + ord(val) - ord('A') + 10
            elif ord(val) >= num_base:
                s = s * 16 + ord(val) - ord('0')
            else:
                print('error')
        print(s)
except:
    pass



'''
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

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