SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Edexcel 1CP2 · Topic 6 · 6.1b

Sequence, Selection
& Iteration in Python

if / elif / else · for · while · Nesting · Conditions

CSZoneEdexcel GCSE Computer Science 1CP2
Sequence

Code Runs Line by Line

name = input("Name: ")
age = int(input("Age: "))
print("Hello", name)
print("Next year you will be", age + 1)
Sequence: instructions are executed in order from top to bottom
Python uses indentation (4 spaces) to define blocks — no curly braces like other languages
Selection — if / elif / else

Making Decisions

score = int(input("Score: "))
if score >= 70:
print("Grade A")
elif score >= 50:
print("Grade B")
else:
print("Grade C")
Always colon after the condition: if condition:
Indented block runs only if condition is True; else is the default if nothing matched
Nested if: put an if statement inside another — useful for multi-condition checks
Iteration — for and while

Repeating Code

# for loop — definite iteration
for i in range(5): # 0, 1, 2, 3, 4
print(i)

# while loop — indefinite iteration
count = 0
while count < 3:
print(count)
count += 1
for: when you know how many times to repeat; range(start, stop, step)
while: when you repeat until a condition becomes False — can run forever if condition never changes
Exam Practice

Have a go at this question

Edexcel-style question
Write Python code that asks the user to enter a number and keeps asking until they enter a number greater than 10.
3 marks
num = int(input("Enter a number: "))
while num <= 10:
num = int(input("Enter a number: "))
print("Done")
Key Takeaways

What to Remember

Sequence: code runs top to bottom; Python uses indentation for blocks
Selection: if / elif / else; always colon; indent the block inside
for: definite (count-controlled); while: indefinite (condition-controlled)
range(start, stop, step): start inclusive, stop exclusive e.g. range(1,6) = 1,2,3,4,5