Year 8 › Python I › Lesson 3 of 5
Year 8 · Spring 2 · Python I if / elif / else
Topic 13 Programming basics
KS3 Computing · A program stores information in variables, works on it with operators, and controls the order with sequence, selection and iteration. Examples are in Python, with Scratch alongside for Year 7.
Programming Computational Thinking Cambridge Lower Secondary Computing 0860
You will learn to Use the comparison operators ==, !=, >, <, >= and <=. Use if, elif and else, with a colon and indentation, to choose one path. Explain why the order of the conditions matters. Use PRIMM to predict the output of a program before you run it.
Success criteria I can write a grade program: 90 and over is an A, and so on down. I can predict the output of five short programs before I run them. I can explain what goes wrong if the lowest grade is checked first.
Variable A named place in memory that holds a value.
Assignment Storing a value in a variable. = in Python, ← in pseudocode.
Casting Changing a value from one data type to another, like int("13").
Concatenation Joining strings together: "7" + "7" = "77".
Selection Choosing a path with if / else.
Iteration Repeating steps: a loop.
Boolean A value that is only True or False.
Infinite loop A loop whose condition never becomes false.
Selection: if, elif, else score = int(input("Score out of 50: "))
if score >= 40:
print("Gold badge!")
elif score >= 25:
print("Bronze badge")
else:
print("Try the Respawn quest") Check the if. True? Run its lines and skip the rest . False? Check the elif. Nothing true? Run the else. ! Watch outOrder matters. If >= 25 came first, a score of 45 would wrongly get Bronze.
★ RememberIndentation (4 spaces) shows which lines are inside the if. The colon : is required.
Mark this lesson as done Saved on this device.
← Previous lesson Variables, data types and arithmetic Next lesson → while loops