每个数字都应替换为拼写出来的名称(零、一、二、三、四、五、六、七、八、九),但我一直在我的新文件中得到这个:
zero0000000001one111111112222222222333three3333334444four4444455555five5555666666six666
这是我的程序:
def numbers(fileName):
#open the inputed file ,prompt for the file
inFile= open(fileName,'r') #this will open the function for writing and reading
outFile=open('converted.txt', 'w')
for line in inFile:
wordList=line.split()
for word in wordList:
if word == '0':
outFile.write("zero")
else:
outFile.write(word)
if word =="1":
outFile.write("one")
#else:
#outFile.write(word)
if word in wordList == "2":
outFile.write("two")
#else:
#outFile.write(word)
if word == ("3"):
outFile.write("three")
#else:
#outFile.write(word)
if word == ("4"):
outFile.write("four")
#else:
#outFile.write(word)
if word == ("5"):
outFile.write("five")
#else:
#outFile.write(word)
if word == ("6"):
outFile.write("six")
#else:
#outFile.write(word)
if word == ("7"):
outFile.write(word)
#else:
#outFile.write(word)
if word == ("8"):
outFile,write(word)
#else:
#outFile.write(word)
if word == ("9"):
outFile.write(word)
#else:
#outFile.write(word)
outFile.write(" ")
outFile.write("\n")
outFile.close()
inFile.close()