Computer Science · High School (9–10) · 3 courses, 30 worked problems, 30 practice questions
Programming is writing instructions that a computer can carry out. This topic covers the building blocks found in every language. Variables and constants store data of a type such as integer, real, string or Boolean. Sequence, selection and iteration control the order of steps: IF statements choose, and FOR, WHILE and REPEAT loops repeat. Arrays hold lists of values, and procedures and functions break a long program into parts. Programs also validate input, handle strings and read and write files. You practise these in pseudocode and in Python.
Choose an answer, then check it. Each one shows a full explanation.
A quiz app stores the number of questions a player has answered so far. Which data type should it use?
Which of these is a correct literal of data type REAL in Cambridge pseudocode?
A shop packs eggs in boxes of six. DECLARE Eggs : INTEGER DECLARE Spare : INTEGER Eggs ← 29 Spare ← MOD(Eggs, 6) OUTPUT Spare What is output?
Which of these is a valid identifier in Cambridge pseudocode?
Each one has a hint, the key idea and a full worked solution.
A small program works out the price of some pens. DECLARE Price : INTEGER DECLARE Pens : INTEGER Price ← 3 Pens ← 4 OUTPUT "Total: ", Price * Pens What is output?
Two values are compared with logical operators. DECLARE A : INTEGER DECLARE B : INTEGER A ← 7 B ← 3 OUTPUT (A > 5) AND NOT (B = 3) What is output?
Two loops start with the same value. DECLARE Level : INTEGER Level ← 50 WHILE Level < 20 DO Level ← Level + 10 ENDWHILE REPEAT Level ← Level + 10 UNTIL Level > 20 OUTPUT Level How many times does each loop body run, and what is output?
A countdown uses a FOR loop with a negative step. DECLARE Count : INTEGER FOR Count ← 9 TO 1 STEP -2 OUTPUT Count NEXT Count How many values are output?
The flowchart sets Count to 0 and inputs a value. While the value is not , it adds 1 to Count and inputs the next value. Then it outputs Count. Which loop does the flowchart show?
Every player in a league of four meets each player, and also plays one practice game alone. A program counts the games. DECLARE Home : INTEGER DECLARE Away : INTEGER DECLARE Games : INTEGER Games ← 0 FOR Home ← 1 TO 4 FOR Away ← Home TO 4 Games ← Games + 1 NEXT Away NEXT Home OUTPUT Games What is output?