代码工作不正确,显示无法理解的数字:



代码工作不正确,显示无法理解的数字:3.612432554629948e + 76显示不可理解的值,它应该是这样的:并应输出:大量,例如:十六进制:8459 f630cd86ddfa329b3d13d5217d45df1d5e9a56a63f6a3d7ab8b794c35c1212月:59864244547079690871082685810675850360550404961977540588162601013229404773394

# Covert a file with lines of hex values in "hex.txt" to decimal
# values and write to "dec.txt"
# NOTE: This program only handles Value errors and replaces them
# with the string XXXXX, no other error handling is performed  
HEXLIST_FILENAME = "hex.txt"
DECLIST_FILENAME = "dec.txt"
def loadHex():
"""
Returns a list of Hex strings from a file

"""
hexList = []
print ("Loading hex list from file...")
try:
inFile = open(HEXLIST_FILENAME, 'r')
except IOError:
print('No such file "hex.txt"')
#more error handeling here
for line in inFile:
hexList.append(line.strip().upper())
print (len(hexList)), "Numbers loaded."
return hexList
def hexToDec(hexString):
"""
Takes in a string representing a hex value

Returns a decimal number string
"""
try:
i=int(hexString,16)
except ValueError:
print('Oops! There was an invalid number in hex.txt...')
print('Invalid number replaced with XXXXX')
i='XXXXX'
return str(i/float(2**21))
def exportDec(decList):
"""

"""
outFile=open(DECLIST_FILENAME,'w')
for num in decList:
outFile.write(num+"n")
outFile.close()
print ("Success! Decimal numbers written to dec.txt")

decList = []
hexVals=loadHex()
for hexnum in hexVals:
decList.append(hexToDec(hexnum))
exportDec(decList)
s=input()('Press Enter to exit...')

不确定为什么在hexToDec方法中将转换值除以2**21:

return str(i/float(2**21))

不需要除法,只要输入

就可以得到正确的输出。
return str(i)

直接从你的hexToDec方法。