Exam preparation · GCSE · about 15 min
Reading and writing exam pseudocode and flowcharts, and translating both ways.
[1 mark]How many times does FOR i = 1 TO 5 run?
[1 mark]Which pseudocode keyword prints something?
[1 mark]In a flowchart, what does a diamond mean?
[1 mark]What does this program print?
for i in range(1, 4):
print(i * i)1 4 9
FOR 1 TO 3 includes 3, so range stops at 4.
[1 mark]You are asked to write an algorithm. What may you use?
Turn the pseudocode in the comment into a working program. It asks for a number of steps, drives that many 10 cm steps while counting the total distance, and prints the total. input() is answered for you with 4.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() # steps = USERINPUT # total = 0 # FOR i = 1 TO steps # MOVE FORWARD 10 # total = total + 10 # OUTPUT "step " + i + ": " + total # NEXT i # OUTPUT "total: " + total
The hint students can ask for: The answer from input() is text, so make it a whole number first. FOR 1 TO steps includes the last one, so the range has to reach one past it. Add the 10 on before you print.
from bugbot import *
connect()
steps = int(input())
total = 0
for i in range(1, steps + 1):
forward(50, distance=10)
total = total + 10
print(f"step {i}: {total}")
print("total:", total)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.