Question: How to parse a nested list to calculate grade averages.

So I am fairly new to maple and haven't really worked with it up until a couple of weeks ago. I am taking a physics course which requires us to do some work in maple and I am struggling to learn some of the concepts behind the data structures.

I have to essentially be able to parse a list of "Student Records" with names and marks received, and then store the data in a new list with the student name, and their average.

Essentially I am given:

[code]
current_marks := [
    [ "Student A", [83,61,75] ],
    [ "Student B",[77,96,64] ],
    [ "Student C", [83,87,85] ]
]:
[/code]

and I need to return a new list consisting of the student and their average in the following format:

[code]
averages := [
    [ "StudentID", average],
    [ "StudentID_2", average],
    ...
]:
[/code]

At first I was trying to use for loops and I got it to work but it just appeared blotted and I figured there was a different way, since we haven't covered for loops in class. After that I had tried to use select to parse through the list and past the list of grades to a function to calculate the averages. But I can't figure out how to pass a list as an argument. The syntax I was trying to use for this was:

[code]
calcAvg := [a1, a2, a3] -> (a1 + a2 +a3) / 3: #Gives the error: invalid operator parameter name.
[/code]

Is there a more efficient way of doing a procedure like this?

Thank you, and I am grateful for any help that you can provide :).

Please Wait...