作为练习,我将数字转换为十六进制值。有没有更专业的方法?
def hexayacheviren(reqem):
if reqem==10:
return "A"
elif reqem==11:
return "B"
elif reqem==12:
return "C"
elif reqem==13:
return "D"
elif reqem==14:
return "E"
elif reqem==15:
return "F"
else:
return reqem
def hexadecimal(n):
cavab=[ ]
i=0
while (n>0):
netice=n%16
cavab.append(hexayacheviren(netice))
i=i+1
n=n//16
string=''.join(str(e) for e in cavab)
cvbstrng = string[::-1]
print (cvbstrng)
hexadecimal(3200)