Sep-09-2022, 08:57 AM
It is a pity you are not allowed to use a dictionary. This makes it difficult to create a nice script.
As stated by Yoriz, this forum requires you to produce a program yourself and then you will get help to make it work. But I can give you some hints about the data structure and algorithm you may use.
Because a dictionary is not allowed, my advice is to create an intermediate data structure, fit for further processing. It should be a list of lists where each sublist starts with the student id, followed by the scores. Like this:
Please try to make a program of this and show it to us. If you get errors, show the complete error message.
As stated by Yoriz, this forum requires you to produce a program yourself and then you will get help to make it work. But I can give you some hints about the data structure and algorithm you may use.
Because a dictionary is not allowed, my advice is to create an intermediate data structure, fit for further processing. It should be a list of lists where each sublist starts with the student id, followed by the scores. Like this:
intermediate = [ [6610013121, 4], [6610021021, 5], [6610000121, 3, 2, 2, 3] ]The algorithm is then:
- Read the given list "d" in pairs of student_id and score.
- Scan the intermediate list to see if student_id already exist as intermediate[i][0]
- If it is: append the score to the sublist; else append a new sublist to the intermediate list containing [student_id, score].
- When this is all done you can start handling the intermediate list. First create an empty list for the results.
- If there are more than 4 scores in a sublist, find and remove the lowest.
- Summarize the scores of the sublist and append them to the results list in pairs of student_id and summarized score.
Please try to make a program of this and show it to us. If you get errors, show the complete error message.