Python题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
import math
while True:
try:
str1 = input()[2:]
sum = 0
j = 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,
}
for i in str1:
a = dict1[i]
ex = len(str1) - 1 - j
sum += a * math.pow(16, ex)
j += 1
print(int(sum))
except:
break
查看12道真题和解析