您可以在代码中添加更多行来执行此操作:
首先创建两个带有字符的列表,一个带有要映射的整数,然后从那些创建dict:
list_1=["A","B","C","D","E","F"]
list_2=[10,11,12,13,14,15]
new_dict={i:j for i,j in zip(list_1,list_2)}现在在最后一行代码中添加这些行,以检查输入的最后一位是否在dict中,然后获取该值的键。
新=余数[:]
for i in new:
for j,k in new_dict.items():
if k==i:
print("{}{}".format(j,''.join(str(x) for x in remainders[::-1][1:])))完成。
完整代码:
list_1=["A","B","C","D","E","F"]
list_2=[10,11,12,13,14,15]
new_dict={i:j for i,j in zip(list_1,list_2)}
number = input("enter a number: ")
number = int(number)
remainders = list()
while number>0:
remainders.append(int(number % 16))
number//=16
new=remainders[:]
for i in new:
for j,k in new_dict.items():
if k==i:
print("{}{}".format(j,''.join(str(x) for x in remainders[::-1][1:])))运行时间:
enter a number: 3877
F25