You need to indent your code properly. Your second
for
loop is currently outside of the first loop, and the final
with
/
write
block is outside of both. From your description, you need everything to execute within the first loop.
with open("input.txt", "r") as a_file:
for line in a_file:
stripped_line = line.strip()
for word in WORDS:
mnemonic = stripped_line.format(x=word)
if check(mnemonic):
print(mnemonic)
with open("print.txt", "a") as i:
i.write(mnemonic)
NB: If you want to write each mnemonic value on a new line in the output file, then you need to write a line separator after each one:
...
with open("print.txt", "a") as i:
i.write(mnemonic)
i.write('\n')
Built-in Functions — Python 3.9.6 documentation[
^]