AQA GCSE Computer Science: Algorithm Questions
While Loops
1. Write a while loop that prints numbers from 1 to 10.
2. Write a while loop that keeps asking the user to enter a number until they enter -1.
3. Write a while loop to find the sum of all even numbers from 2 to 100.
4. Write a while loop that simulates a simple login system with 3 attempts.
5. Trace table: What will be the output of the following code?
count = 0
while count < 5:
print(count)
count += 1
Fill in the trace table with the values of 'count'.
For Loops
6. Write a for loop that prints all elements in a list of names.
7. Write a for loop that calculates the factorial of a given number.
8. Write a for loop that prints the multiplication table of 5.
9. Write a for loop to find the total of a list of numbers.
10. Trace table: What will be the output of the following code?
for i in range(3):
print(i)
Fill in the trace table with the values of 'i'.
Nested Iteration
11. Write a nested for loop to print a 3x3 grid of numbers.
12. Write a nested loop that prints a multiplication table from 1 to 5.
13. Write a nested loop that prints all combinations of two dice rolls.
14. Write a nested loop that iterates through a 2D list and prints each element.
15. Trace table: What will be the output of the following code?
for i in range(2):
for j in range(2):
print(i, j)
Fill in the trace table with the values of 'i' and 'j'.