Skip to content
evolve.tt

After Hello, World, keep a list of class-test marks, total them, and print an average. The pass mark is your teacher’s, not a CSEC grade.

The basic Python course ends with a quiz and a bonus on lists. This is the program you write next. It is also one of the three small programs in from CXC IT to a junior developer: something you can run, and one bug you can explain.

Marks 71, 48, 63, 55 and 80. Total 317. Average 63.4. The 50 is not a CSEC grade.
Infographic 317 divided by 5 is 63.4. The pass mark is the teacher’s. Drawn for evolve.tt.
  1. Store the marks

    One list. One class test. Not a year of results.

  2. Total, then divide

    The average can be a decimal. That is expected.

  3. Compare with the teacher's mark

    50 here is an example. It is not a CXC grade.

What the program does

Go to online-python.com. You do not install anything. Paste one block, run it, read the output, then change a number and run it again.

If a list is new, the bonus lesson in the first course is the longer explanation. You only need this much: a list keeps several values in order, and you can walk through it with for.

These five numbers are a class test out of 100. They are not CSEC results. Grades I, II, and III are the grades schools treat as passes, which is the whole point of a class test is not a CSEC grade.

A marks book for one class test
marks = [71, 48, 63, 55, 80]
total = 0
for mark in marks:
total = total + mark
average = total / len(marks)
print("Students:", len(marks))
print("Total:", total)
print("Average:", average)
teacher_pass = 50
print("Pass mark on this test:", teacher_pass)
for mark in marks:
if mark >= teacher_pass:
print(mark, "met this test's pass mark")
else:
print(mark, "did not")

Run it. The average is 63.4, not a whole number. total / len(marks) in Python 3 keeps the decimal. Do not round it away to make the printout look neat. 63.4 is the average of those five marks.

The 50 is the same example pass mark as lesson 2 of the first course. It is a number a teacher might choose. Change it to 60 and run the program again. Two more marks fall below. The official CSEC scale did not move. Your example did.

Replace the five numbers with marks from a test you are allowed to use. Your own scores are fine. A classmate’s name is not. Keep numbers only.

Then add one mark and run it again. If the average does not change, the new mark never entered marks. That is the bug to be able to explain: the list is the only place the total looks.

It does not store the marks anywhere after you close the tab. The browser forgets them. A file comes later. Do not paste a spreadsheet of a real class into a chatbot to “improve” this program. Names and scores of other people stay out. The rule is what never to paste.

It also does not convert a percentage into a CSEC grade. There is no line of code that should try.

Discussion

View all discussions on GitHub