The first programme that does not do the same thing every time
Every programme so far has run straight down the page, doing all nine lines in order, whatever the data was. This one has to choose. Above the pass mark it says PASS, below it says FAIL, and it decides for itself which.
marks >= pass_mark is a condition. Python works it out, gets one of those two answers, and uses it to decide which lines to run.The six comparisons
| a > b | a is bigger | a < b | a is smaller |
|---|---|---|---|
| a >= b | bigger, or exactly equal | a <= b | smaller, or exactly equal |
| a == b | exactly equal | a != b | not equal |
Note the double equals. A single = puts a value into a box — you have used it since problem 2. Asking whether two things are equal is ==, and Python refuses to let you confuse the two inside a condition.
>= says so; > does not. On almost every student in the class the two behave identically, so the mistake stays hidden until the one student who scored exactly 35 gets told they failed.Whenever you write a comparison, test it on the boundary value. Not near it — on it.
Most languages use curly brackets for this and treat the spacing as decoration. In Python the spacing is the structure. Move a line in or out and you have changed what the programme does — often without any error at all.
if line and the else line end in a colon. It is Python's way of saying "a block belongs to this line, and it starts on the next one". Forget it and Python tells you plainly, which is the kindest of the mistakes in this problem.What you are building
Three lines when the student passes, three when they fail — with the middle one different. The last line appears either way.
elif in problem 11.Build the programme
Your plan
The steps still to place
The whole programme is laid out below. Five pieces are missing, and two of them are nothing but blank space — which in Python is as much a part of the programme as any word.
Leave nothing on "choose…". A wrong pick does not always cause an error — sometimes it just prints something you did not expect, which is the harder kind of mistake to spot.
Run and read
Here is the whole programme. Both numbers are yours to change. When it works, come back and set the marks to exactly the pass mark — that is the value that catches a comparison written slightly wrong.