Computing · Year 6
Bell.Study
Logical reasoning: predicting behaviour
Working out exactly what a program will do by tracing through it step by step
- 1
What does it mean to 'trace' a program? A) Step through each line of code in order to work out what happens B) Draw round it with a pencil C) Send the code to another computer D) Delete it from the system
Answer: - 2
Look at this pseudocode. What is OUTPUT? SET x TO 5 SET x TO x + 3 OUTPUT x A) 8 B) 5 C) 3 D) 15
Answer: - 3
True or false? A computer always follows code in the exact order it is written (unless told to loop or branch). A) True B) False
Answer: - 4
What is logical reasoning? A) Using rules and facts to work out what is true B) Guessing at random C) Drawing pictures D) Listening to music
Answer: - 5
Look at this pseudocode. SET age TO 12 IF age >= 13 THEN OUTPUT 'Teenager' ELSE OUTPUT 'Not a teenager yet' END IF What is OUTPUT? A) Not a teenager yet B) Teenager C) Both messages D) Nothing
Answer: - 6
Trace this code. SET total TO 0 REPEAT 3 TIMES SET total TO total + 2 END REPEAT OUTPUT total What is OUTPUT? A) 6 B) 3 C) 2 D) 0
Answer: - 7
True or false? This code OUTPUT 'Yes'. SET a TO 4 SET b TO 7 IF a > b THEN OUTPUT 'Yes' ELSE OUTPUT 'No' END IF The OUTPUT will be 'Yes'. A) True B) False
Answer: - 8
Put these tracing steps in order for the code below. SET n TO 1 REPEAT 2 TIMES SET n TO n * 2 END REPEAT OUTPUT n Put these in order: n is now 1, Loop pass 1: n becomes 2, Loop pass 2: n becomes 4, OUTPUT 4
Answer: - 9
Trace this code. SET score TO 7 IF score >= 5 AND score <= 10 THEN OUTPUT 'In range' ELSE OUTPUT 'Out of range' END IF A) In range B) Out of range C) Both messages D) Nothing
Answer: - 10
Trace this code. SET count TO 0 REPEAT 4 TIMES SET count TO count + 1 IF count = 3 THEN OUTPUT 'Three!' END IF END REPEAT OUTPUT count Which is correct? A) It prints 'Three!' once and then prints 4 B) It prints 'Three!' four times C) It prints nothing D) It prints 'Three!' and then 3
Answer:
Answer key
Logical reasoning: predicting behaviour · for parents and teachers
- 1
Step through each line of code in order to work out what happens
Tracing a program means going through each line in order, working out what each step does, so you can predict the final result.
- 2
8
x is set to 5, then x becomes x + 3 (which is 8). OUTPUT shows 8.
- 3
True
Yes. Computers follow instructions in order. They only repeat or skip lines if a loop or IF tells them to.
- 4
Using rules and facts to work out what is true
Logical reasoning uses facts and rules to figure out what must be true.
- 5
Not a teenager yet
12 is not >= 13, so the ELSE branch runs and OUTPUT shows 'Not a teenager yet'.
- 6
6
The loop runs 3 times, adding 2 each time: 0 -> 2 -> 4 -> 6. OUTPUT shows 6.
- 7
False
4 is not greater than 7, so the ELSE branch runs. OUTPUT shows 'No', not 'Yes', so the statement is false.
- 8
n is now 1, Loop pass 1: n becomes 2, Loop pass 2: n becomes 4, OUTPUT 4
Tracing shows n: 1 -> 2 -> 4. After two passes, the loop ends and OUTPUT shows 4.
- 9
In range
7 is >= 5 AND 7 is <= 10, so both parts are true. OUTPUT shows 'In range'.
- 10
It prints 'Three!' once and then prints 4
On the third pass, count is 3 so 'Three!' prints. After all 4 passes, count is 4 and that prints at the end.