Python assignments - help would be appreciated

Tbh I’m completely lost so I’m just gonna post all three assignments - any help or input which commands to use will be most appreciated! :

  1. Create a function called read_data , that takes a filename as argument. The function should open the file, and read its contents into a list of list of floats, where the outer list corresponds to the lines of the file, and the inner lists correspond to the columns (that is, convert the strings of each line to a list of two numeric values, and append them to an outer list). The function should return this list. Test the function by calling it on the experimental_results.txt file like this:

list_of_rows = read_data(‘experimental_results.txt’)

  1. Write a function called calc_averages that takes a list of list of floats as input, and calculates the average value for each column by iterating over the rows. The function should return these two values. Test the function by calling it like this:

col1_avg, col2_avg = calc_averages(list_of_rows)
print(col1_avg, col2_avg)

  1. Write a function called transpose_data that turns the list of lists around so that it becomes a list of columns, rather than a list of rows. This means that the outer list now has two elements each containing a list of all the values in the corresponding column. In other words, if I want to access the 26th value in the 2nd column, I would now index with [1][25] instead of [25][1]

This is my “progress” on assignment 1 so far. Quite lost if I’m on the right path.

You’ll need to address the “invalid syntax” error first. It’s pointing to line 1:

def read_data('experimental_results.txt'):

Your function parameters shouldn’t be strings like that, but rather something like:

def read_data(filename):

Notice that I left off the quotation marks. Then on line 5:

with open(filename) as f:

See if that helps. You may see other syntax errors after fixing the first, for example maybe your indent is not correct for the return line.

Thanks for the reply and help :slightly_smiling_face:
I also got some other help, so got the problem solved. But really appreciate, cheers :slight_smile: