Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
The marks, already sorted from the highest, are [95, 90, 90, 90, 80, 75, 75]. Work out the rank of each mark, where equal marks share a rank and the next rank is skipped. Then write a function that computes the ranks.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. The rank of a mark is one more than the number of marks that are bigger than it.
| Mark | Marks above it | Rank |
|---|---|---|
| 95 | 0 | 1 |
| 90 | 1 | 2 |
| 90 | 1 | 2 |
| 90 | 1 | 2 |
| 80 | 4 | 5 |
| 75 | 5 | 6 |
| 75 | 5 | 6 |
The function.
Check. The output is [1, 2, 2, 2, 5, 6, 6], as in the table.
Answer: [1, 2, 2, 2, 5, 6, 6].
Log in to join the discussion.
Loading…