
PRIMM Task – Predict & Run
At the ‘predict’ & ‘run’ stages students work entirely with example code. They should inspect it carefully and write a prediction about what it will do.
They then run the code and compare the result to their prediction.
Advanced If…Else Statements – Nesting
Nesting is the term for putting programming constructs of the same type inside each other.
These examples use nested if statements – if statements inside other if statements.
The nested statement will only be run if the condition above it is True
.
if num1 > 20:
print("Bigger than 20")
# nested if is indented so is part of the 'if' statement above.
if num1 > 50:
print("and bigger than 50")
else:
print("but not bigger than 50")
Errors & Misconceptions To Watch Out For
- Check the indentation very, very carefully
- Count the
if
s & else
s, are there an equal number?
- Check your logic, when should each branch run? Is the if statement nested into the correct branch – try drawing out a flowchart on paper to map the possible pathways through the program.