You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson brings together all the programming concepts covered in this course and provides exam-style questions with worked solutions. Practising these questions will prepare you for the programming section of your GCSE Computer Science exam (AQA Paper 1 / OCR J277 Paper 2).
Before attempting practice questions, make sure you are confident with:
| Question Type | What to Expect |
|---|---|
| Trace table | Follow code step by step, recording variable values at each stage |
| Write pseudocode/Python | Write a program or subroutine to solve a given problem |
| Identify errors | Find and correct syntax or logic errors in given code |
| Explain code | Describe what a given piece of code does, line by line |
| State the output | Determine what a program will display when run |
| Compare constructs | Explain the difference between two programming concepts |
Trace the following pseudocode and complete the trace table.
x ← 5
y ← 3
FOR i ← 1 TO 4
x ← x + y
y ← y + 1
ENDFOR
OUTPUT x
| Iteration | i | x | y |
|---|---|---|---|
| Start | — | 5 | 3 |
| 1 | 1 | 8 | 4 |
| 2 | 2 | 12 | 5 |
| 3 | 3 | 17 | 6 |
| 4 | 4 | 23 | 7 |
Output: 23
Exam Tip: Work through each iteration carefully and update all variables in the correct order. A common mistake is updating variables in the wrong sequence within a single iteration.
Write a function called is_even that takes an integer parameter and returns True if it is even and False otherwise.
SUBROUTINE is_even(number)
IF number MOD 2 = 0 THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDSUBROUTINE
def is_even(number):
if number % 2 == 0:
return True
else:
return False
Or more concisely:
def is_even(number):
return number % 2 == 0
Write a program that asks the user to enter 5 numbers, stores them in an array, and then outputs the total and the average.
numbers = []
for i in range(5):
value = int(input(f"Enter number {i + 1}: "))
numbers.append(value)
total = 0
for num in numbers:
total += num
average = total / len(numbers)
print(f"Total: {total}")
print(f"Average: {average}")
numbers ← []
FOR i ← 1 TO 5
OUTPUT "Enter number ", i, ":"
value ← INT(USERINPUT)
numbers.APPEND(value)
ENDFOR
total ← 0
FOR EACH num IN numbers
total ← total + num
ENDFOR
average ← total / LEN(numbers)
OUTPUT "Total: ", total
OUTPUT "Average: ", average
The following code is supposed to check if a number is between 1 and 100 inclusive. Identify and fix the error.
number = input("Enter a number: ")
if number >= 1 and number <= 100:
print("Valid")
else:
print("Invalid")
The error is that input() returns a string, not an integer. The comparison with 1 and 100 will fail or produce unexpected results. The fix is:
number = int(input("Enter a number: "))
if number >= 1 and number <= 100:
print("Valid")
else:
print("Invalid")
Write a program that reads a file called "names.txt" and counts how many names are stored in it (one name per line).
count = 0
with open("names.txt", "r") as file:
for line in file:
if line.strip() != "":
count += 1
print(f"Number of names: {count}")
count ← 0
file ← OPENREAD("names.txt")
WHILE NOT file.ENDOFFILE()
line ← file.READLINE()
count ← count + 1
ENDWHILE
file.CLOSE()
OUTPUT "Number of names: ", count
Write a function that takes a string and returns the number of uppercase letters it contains.
def count_uppercase(text):
count = 0
for char in text:
if char.isupper():
count += 1
return count
print(count_uppercase("Hello World")) # Output: 2
SUBROUTINE count_uppercase(text)
count ← 0
FOR i ← 0 TO LEN(text) - 1
IF ASC(text[i]) >= 65 AND ASC(text[i]) <= 90 THEN
count ← count + 1
ENDIF
ENDFOR
RETURN count
ENDSUBROUTINE
Write a login system that allows a maximum of 3 attempts and validates that the username is not empty.
correct_user = "admin"
correct_pass = "Secure99"
attempts = 0
while attempts < 3:
username = input("Username: ")
if len(username) == 0:
print("Username cannot be empty.")
continue
password = input("Password: ")
if username == correct_user and password == correct_pass:
print("Login successful!")
break
else:
attempts += 1
print(f"Incorrect. {3 - attempts} attempts remaining.")
if attempts == 3:
print("Account locked.")
score, total, count not x, y, z.= (assignment) and == (comparison).file.CLOSE()).flowchart TD
A[Read question carefully] --> B{Pseudocode or Python?}
B -->|Pseudocode| C[Use AQA keywords]
B -->|Python| D[Use Python syntax]
C --> E[Plan with comments]
D --> E
E --> F[Write the solution]
F --> G[Trace with sample data]
G --> H{Correct output?}
H -->|No| I[Fix logic errors]
I --> G
H -->|Yes| J[Check edge cases]
J --> K[Submit answer]
Trace the pseudocode and state the output:
total ← 0
FOR i ← 1 TO 3
FOR j ← 1 TO 2
total ← total + (i * j)
ENDFOR
ENDFOR
OUTPUT total
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.