这是我的密码
sentext = open("urSentence.txt", "w")
UserSen = input("Enter your sentence of your choice, ")
print (UserSen)
sentext.close()
postext = open("ThePos.txt", "w")
listSplit = UserSen.split()
X = {} #this will make the words in a sentence assigned to a number
position=[]
for i,j in enumerate(listSplit): #"i" will count how many words there are in the sentence
if j in X:
position.append(X[j])
else:
X[j]=i
position.append(i)
print (position)
postext.close()
它生成文件,但不保存任何内容。我做错什么了?你知道吗
你从未以任何方式写过任何文件。你可以用几种方法来做。既然您已经在使用类似python3的
print
函数,请尝试file
参数:print
函数不会写入文件。您需要显式地写入它。你知道吗同样地:
相关问题 更多 >
编程相关推荐