Code
import stringdef main ():# Get input filefile = input("Please enter the name of the original file: ")infile = open(file, 'r')# get output fileotherFile = input("Please enter the name of the file to write to: ")outfile = open(otherFile, 'w')# Change filefor line in infile:words = line.split( )for word in words:counter = 0for letter in word:if not letter in string.punctuation:counter += 1if counter == 4:if "." in word:word = "****."elif "," in word:word = "****,"elif "?" in word:word = "****?"elif "!" in word:word = "****!"else:word = "****"print (word + " ", file = outfile, end = "")# close filesinfile.close()outfile.close()if __name__=='__main__':main ()
Output
run the code buddy :)
0 Comments
Post a Comment