For Routine 8, problem 5; the output goes to the console using print statments, not to a file using write statements.
The code you put in Moodle won't have a main function.
If you want test out your code in Thonny, you would need to organize it this way:
fin = open(filename, 'r')
# code to read through the file and process it
You also need a 2nd file with the data values named data1.txt which is in the same folder as the .py file.
The only part that you put in Moodle is the code from def fileAverage(filename): up to, but not including def main():