JIT — Intro to Data Science · Python Lab · Problem 10 of 30

Pass or fail

The first programme that chooses what to do — and where four blank spaces decide which lines belong to the decision.

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.

New word — condition A question with only two possible answers: True or False. 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 > ba is biggera < ba is smaller
a >= bbigger, or exactly equala <= bsmaller, or exactly equal
a == bexactly equala != bnot 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.

Careful — the boundary is where marking schemes are won and lost A student who scores exactly the pass mark has passed. >= 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.
New word — block, and why the spaces matter Python marks out which lines belong to a decision by indenting them — pushing them in, conventionally by four spaces:
if marks >= pass_mark: print("PASS") else: print("FAIL") print("Result recorded")
The two indented lines each belong to a branch. The last line is pushed back out to the margin, so it belongs to nobody and runs every time.
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.
The colon Both the 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

Marks: 42 PASS Result recorded

Three lines when the student passes, three when they fail — with the middle one different. The last line appears either way.

Coming later Two outcomes need one condition. Grades of A, B, C, D and F need several, tested in the right order, and that is 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.

Your programme

Output

Nothing has run yet.