-2
我想寫一個文件,審查單詞「冬天」,但由於某種原因,我的代碼不工作,雖然我沒有錯誤。幫幫我!問題與審查蟒蛇腳本
filename = input("Enter file name (without extension): ")
file1 = filename+".txt"
file2 = filename+"_censored.txt"
word = input("Enter the word you are searching for: ")
#In this case, the input would be "winter"
print("\nLooping through the file, line by line.")
in_text_file = open(file1, "r")
out_text_file = open(file2,"w")
for line in in_text_file:
print(line)
out_text_file.write(line)
n = [ ]
def censor(word, filename):
for i in text.split(''):
if i == word:
i = "*" * len(word)
n.append(i)
else:
n.append(i)
return ' '.join(n)
in_text_file.close()
out_text_file.close()
開始通過固定的壓痕 – njzk2
你的縮進是靠不住的。你能解決它嗎? – James