Write an automated censor program that reads in the text fro
Write an automated censor program that reads in the text from a file and creates a new file where all of the four- and five-letter words have all but their first and last characters replaced with \"*\". For instance, \"dart\" would be replaced by \"d**t\" and \"slime\" with \"s***e\". Words of other lengths should be unchanged. You can ignore punctuation, and you may assume that no words in the file are split across multiple lines.
Solution
code:
fr = open(\"input.txt\",\'r\')
fw = open(\"output.txt\",\'w\')
lines = fr.readlines()
for line in lines:
words = line.split()
newline=\"\"
for word in words:
newword=\"\"
if len(word)==4 or len(word)==5:
newword+=word[0]
for i in range(0,len(word)-2):
newword+=\"*\"
newword+=word[len(word)-1]
newline+=newword+\" \"
else:
newline+=word+\" \"
fw.write(newline+\'\ \')
fw.close()
