Conditions use comparison operators: ==, !=, >, <, >=, <=
Indentation (4 spaces or 1 tab) is mandatory in Python — it defines the block
elif is optional and can be repeated; else is optional and covers all remaining cases
3. Iteration (loops)
Iteration allows code to repeat. Python has two types of loop:
for loop — count-controlled iteration
Used when you know exactly how many times to repeat:
# for loop — repeats a fixed number of timesfor i inrange(5): # i = 0, 1, 2, 3, 4print("Count:", i)# range(start, stop, step)for i inrange(1, 11): # 1 to 10 (not 11)print(i)for i inrange(0, 10, 2): # 0, 2, 4, 6, 8print(i)
while loop — condition-controlled iteration
Used when you don't know how many times to repeat — loop continues as long as a condition is True:
# while loop — repeats while condition is Truepassword = ""while password != "secret123": password = input("Enter password: ")print("Access granted!")
Comparison: for vs while
for loop
while loop
Count-controlled (fixed number of iterations)
Condition-controlled (unknown iterations)
Uses range() or iterates over a collection
Continues while condition is True
Loop variable managed automatically
Must manually manage the condition variable
Example: repeat 10 times
Example: keep asking until valid input
Nested Structures
You can put loops inside loops, and if statements inside loops:
# Nested loop example — multiplication tablefor i inrange(1, 4):for j inrange(1, 4):print(i * j, end=" ")print()# Selection inside a loopfor i inrange(1, 11):if i % 2 == 0:print(i, "is even")else:print(i, "is odd")
Exam tip: The Edexcel paper 2 is a practical Python exam on computer. You'll need to write working code. Practice tracing through loops mentally — know what each iteration does. Common exam tasks: count values in a list, find maximum, validate user input using while.
⚠️ Common Mistakes
Missing the colon after if/elif/else/for/while — causes SyntaxError
Infinite while loop — forgetting to update the condition variable inside the loop
✅ Notes completed!
▶
Video coming soon
Click slide or press arrow keys to navigate
✍️
Worksheet — 6.1b Sequence, Selection & Iteration
8 Edexcel-style questions · instantly marked
Q1Name the three fundamental programming constructs and briefly describe each.[6]
✅ Mark scheme
Sequence: instructions executed one after another, in order [1]; Selection: a decision/condition that determines which code block executes [1]; Iteration: code that repeats (loops) [1]. 1 mark each for correct name, 1 mark each for correct description. Max 6.
Q2Write Python code using a while loop that keeps asking the user to enter a number between 1 and 10 until they do so. When valid, print "Valid input!"[4]
✅ Mark scheme
num = int(input("Enter a number 1-10: ")) [1]; while num < 1 or num > 10: [1]; (indented) num = int(input("Enter a number 1-10: ")) [1]; print("Valid input!") [1].
Q3Trace through this code and state what is printed: for i in range(2, 10, 3): print(i)[2]
✅ Mark scheme
Prints: 2 [1]; 5 [1]; 8 [1] — range(2, 10, 3) generates 2, 5, 8 (stops before 10). [Award 2 marks for all three correct, 1 mark for two correct.]
Q4A student writes this code. Identify ALL errors: if score > 50 print("Pass") else print("Fail")[2]
✅ Mark scheme
Missing colon after condition (should be if score > 50:) [1]; missing colon after else (should be else:) [1]; also missing indentation on both print statements (accept this as a third error).
Q5Explain when you would use a for loop rather than a while loop.[2]
✅ Mark scheme
Use a for loop when the number of iterations is known in advance/fixed [1]; e.g. counting from 1 to 10, or processing each item in a list. Use a while loop when the number of iterations depends on a condition that may change at runtime [1].
Q6Write Python code to print all even numbers from 0 to 20 using a for loop and selection (if statement).[3]
✅ Mark scheme
for i in range(0, 21): [1] (accept range(21) or range(0,22,2) — give full marks for range(0,22,2) without if statement); if i % 2 == 0: [1]; print(i) [1]. (Alt: for i in range(0, 21, 2): print(i) — award 3 marks.)
Q7What is an infinite loop? Give an example of code that would cause one and explain how to fix it.[3]
✅ Mark scheme
A loop that never terminates because its exit condition is never met [1]; Example: count = 1; while count > 0: print(count) — count stays positive forever [1]; Fix: update the condition variable inside the loop so it eventually becomes False, e.g. count -= 1 [1].
Q8Write a Python program that asks a user to enter 5 numbers one at a time, then prints the largest number entered.[5]
✅ Mark scheme
largest = None (or ask first number before loop) [1]; for i in range(5): [1]; num = int(input("Enter number: ")) [1]; if largest is None or num > largest: [1]; largest = num [1]; print("Largest:", largest) — awarded even if outside loop [1]. Max 5.
Topic Quiz
Q 1 of 15
You scored
out of 15
Click to reveal definition
🎉
Session complete!
Term
Definition
🎯
Mini Test — Sequence, Selection & Iteration
Timed exam-style test — 10 minutes.
⏱10:00
Section A — Multiple Choice [5 marks]
Q1What values does range(1, 8, 2) generate?[1]
Q2Which construct should you use when you don't know in advance how many times to repeat?[1]
Q3What is the error in: if x = 5: print("five")[1]
Q4In Python, what marks the body of an if statement or loop?[1]
Q5How many times does this loop execute: for i in range(3, 3): print(i)[1]
Section B — Short Answer
Q6Write Python code that asks a user for a password and keeps asking until they type "letmein". Then print "Welcome!".[3]
Q7Explain the difference between if/elif/else. When would you need elif rather than just else?[2]
Mark schemeif checks the first condition [1]; elif (else-if) checks another condition only if the previous was false — allows multiple different conditions to be tested [1]; else catches everything not caught by if/elif [1]. elif is needed when there are more than two possible outcomes (e.g. grade A, B, C, or F based on score ranges).