def filter_ly_words(text):
words = text.split()
filtered_words = [word for word in words if not word.endswith("ly")]
return " ".join(filtered_words)
def main():
input_file_name = "input.txt"
output_file_name = "output.txt"
try:
with open(input_file_name, "r") as input_file:
input_content = input_file.read()
filtered_content = filter_ly_words(input_content)
with open(output_file_name, "w") as output_file:
output_file.write(filtered_content)
print("Contents copied excluding words ending in 'ly'.")
except FileNotFoundError:
print("The input file was not found.")
if __name__ == "__main__":
main()
Replace "input.txt" with the name of the file you want to read from, and "output.txt" with the desired name for the file where the filtered content will be copied to. The program reads the content of the input file, filters out words ending in "ly", and then writes the filtered content to the output file. Just make sure both the input file and the output file are in the same directory as the script or provide the full paths to the files.