Term 1 round-up
Answers are for parents and teachers.
1
Work these out by hand first, and then say what Python shows: (a) 4 + 6 * 2 (b) (4 + 6) * 2 (c) 30 / 5 / 2 (d) 2 ** 3 + 4.
(a) 16 (b) 20 (c) 3.0 (d) 12. Check that division gives a real number (3.0, not 3) and that brackets were worked out first.
2
This program should show the cost of some stickers. The user types 3 and then 0.25. (a) What does it show? (b) What should the answer be, worked out by hand? (c) Name the kind of error and write the corrected line.
Python
1count = int(input("Stickers? ")) 2each = float(input("Price of one sticker? ")) 3total = count + each 4print("Total:", total)
(a) It shows Total: 3.25. (b) 3 × 0.25 = 0.75. (c) It is a logic error: the line adds when it should multiply. The correct line is total = count * each.
3
Draw a flowchart for a recycling bank: the user types the kilograms of paper. If it is 20 or more, it outputs Collect a sticker; otherwise it outputs Keep collecting. Trace it for 19, 20 and 21.
Start, INPUT kg, diamond kg >= 20?, yes: OUTPUT "Collect a sticker", no: OUTPUT "Keep collecting", Stop. 19 gives Keep collecting; 20 and 21 give Collect a sticker.
4
Write a MicroPython program that shows a diamond when the board is shaken and a small square when button A is pressed. The picture on the lights stays until the other event happens.
Program (each → is 4 spaces of indentation): 1 from microbit import * | 2 while True: | 3 → if accelerometer.was_gesture("shake"): | 4 → → display.show(Image.DIAMOND) | 5 → if button_a.is_pressed(): | 6 → → display.show(Image.SQUARE_SMALL)
5
Choose one idea from Term 1: casting, boundary tests, sub-routines or thresholds. Explain it to a younger child in three sentences and give one example.
Any clear explanation with a correct example is fine, for example: ‘A boundary test uses the exact number where a rule changes. If a ride needs 120 cm, test 119 and 120. This finds mistakes such as > and >= mixed up.’