The line that says 'print(text)' is where the outputs are being generated. So you could instead write that to a file, like (at the same indent level where print is):
Originally Posted by Bohandas
Or if you're running this from a console, you can add '> output.log' to print to a file rather than printing to the console. Like 'python whatever_program_file.py arg1 arg2 arg3 > output.log' where whatever_program_file.py is the name of this code file, and the arg1 arg2 arg3 are whatever and however many command-line arguments you're currently using.
f = open("output.log","a")