Course 5.1Lesson 5 of 5
In this project we write a marks tracker for a class. Two lists hold the names and the marks. The program works out the class size, the total, the average, the highest and the lowest mark with the name of each student, makes a list of the students who passed, and shows the marks from the highest. We plan the report first, build it in small steps, test it with a small list whose answers we know, and extend it with grades, a failed list and a new student. The project uses lists, loops, sum, max, min, index, append and sorted.
Try the code and the simulations beside the lesson.
After this lesson you can
A teacher has the names and the marks of five students. The teacher wants a report with
A small list helps. We use five students, and work out the answers by hand.
| Name | Mark |
|---|---|
| Asha | 72 |
| Ravi | 85 |
| Meera | 64 |
| Kabir | 90 |
| Ana | 58 |
These are the answers that the program must give.
A program that works for one list may be wrong for another. Change the data, work out the answers by hand first, and compare. Test these cases.
index give? It gives the first one.Set the pass mark above 90. Nobody passes, and the list passed stays empty: [].
Pick one or two, and do them without looking at a solution. Test after each one.
if, elif, else ladder inside the loop, and print name, mark, grade.append on both lists, and show that the report changes.names and marks stop matching. Never sort() one of two paired lists. Use sorted() for a copy.len(names) when the lists differ in length. Keep them the same length.index finds the first match only.Start with two quick questions. Each New numbers gives you a fresh one, so you can practise as long as you like.
Then the labs and the problems:
sorted() when you must keep the original order.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
sorted() and not sort() in the tracker?marks.index(max(marks)) give?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.