Practical Examples (OCR Pseudocode & Python)
Part of Iteration (Loops) — GCSE Computer Science
This study notes covers Practical Examples (OCR Pseudocode & Python) within Iteration (Loops) for GCSE Computer Science. Revise Iteration (Loops) in Programming for GCSE Computer Science with 15 exam-style questions and 8 flashcards. This is a high-frequency topic, so it is worth revising until the explanation feels precise and repeatable. It is section 5 of 7 in this topic. Use this study notes to connect the idea to the wider topic before moving on to questions and flashcards.
Topic position
Section 5 of 7
Practice
15 questions
Recall
8 flashcards
Practical Examples (OCR Pseudocode & Python)
Example 1: Sum Numbers 1 to 100
OCR Pseudocode:
total = 0
for i = 1 to 100
total = total + i
next i
print("Sum: " + total)
// Output: Sum: 5050
Python Equivalent:
total = 0
for i in range(1, 101):
total = total + i
print("Sum:", total)
# Output: Sum: 5050
Example 2: Guessing Game
secretNumber = 42
guess = 0
attempts = 0
while guess != secretNumber
guess = input("Guess the number: ")
attempts = attempts + 1
if guess < secretNumber then
print("Too low!")
elseif guess > secretNumber then
print("Too high!")
endif
endwhile
print("Correct! You took " + attempts + " attempts")
Example 3: Input Validation with DO-WHILE
do
age = input("Enter your age (0-120): ")
until age >= 0 AND age <= 120
print("Valid age entered: " + age)