Two languages, one plan
Answers are for parents and teachers.
1
Copy and complete the table.
| Python | MicroPython |
|---|---|
| time.sleep(4) | sleep(?) |
| time.sleep(0.1) | sleep(?) |
| time.sleep(?) | sleep(2500) |
| time.sleep(10) | sleep(?) |
4 seconds = 4000 ms; 0.1 second = 100 ms; 2500 ms = 2.5 seconds; 10 seconds = 10000 ms. Remember that 1 second is 1000 milliseconds.
2
Write the Python program for this flowchart, and say what it prints. Then write the MicroPython program.
Python: boxes = 6, pens_per_box = 12, total = boxes * pens_per_box, then print(total). It prints 72. MicroPython: from microbit import *, the same three lines, then display.scroll(total). The * in the calculation multiplies, but the * after import means everything.
3
Copy the table and write AND, OR or NOT for each situation. Give a reason.
| Situation | Operator? | |
|---|---|---|
| 1 | A hall light comes on if the front sensor or the back sensor sees movement | ? |
| 2 | A toy rocket launches only when two buttons are pressed together | ? |
| 3 | A night-light stays on unless the off button is pressed | ? |
1 OR: either sensor is enough. 2 AND: both buttons are needed, so no child can start it by accident with one hand. 3 NOT: the light is on when the switch is not pressed.
4
A program shows a heart for 2 seconds when A is pressed, and then clears the screen. Write a test plan with three tests, with the expected outcomes.
Model answer: Test 1, A pressed, a heart is shown. Test 2, A pressed, after 2 seconds the screen is clear. Test 3, no button pressed, the screen is clear. Any three sensible tests with expected outcomes that are decided before testing are correct.
5
In the micro:bit program the line from microbit import * and the line total = price * 3 both contain a star. Explain what the star means in each line.
In the import line the star means everything: bring in all of the micro:bit code. In the second line the star is the arithmetic operator for multiply, so total is price times 3.