Did the student pass?
Enter marks in maths, science and English and run a result program: it works out the total and the percentage, checks with AND that every subject is passed, and then uses nested if / else to give the division. Find the marks that reach each branch.
Core concept
Conditions can be joined with AND (all must be true) and OR (one is enough), and an if / else can sit inside another, so the program checks one question after another until one is true
Topic: Decision making
A school result is a chain of decisions. First: did the student pass every subject? A student who scores 95 in two subjects but 25 in the third has still failed. That check joins three condition: A question with a yes or no answer that decides what the program does next. All key words with AND: maths >= 35 AND science >= 35 AND english >= 35 is true only if all three are true. (With OR, one true part would be enough.) Only then does the program look at the percentage, from the top: 80 or more is a distinction; if not, 60 or more is a first division; if not, 45 or more is a second division; otherwise just a pass. Each ELSE IF is asked only when every question above it was false.
What you will learn
- Work out a total and a percentage in a program.
- Explain when a condition joined with AND or OR is true.
- Trace nested if / else and say which branch runs.
- Find inputs that reach a given branch, and complete a missing condition.
Before you start
- Know if / else and the signs >, >= and <.
Materials
- Your own (or made-up) marks for three subjects
Equipment
- None
Procedure
- Run the program with the starting marks and see the division.
- Make one subject fail and run it again.
- Find marks that give a distinction.
- Answer the practice challenges.