GRADE 7 · COMPUTING · UNIT 2 · LESSON 2.3

Decomposing problems: Creating a smart solution

Using Python with the micro:bit

Read a little. Try the workbook. Check your answers. Choose one section below to get started.

7 fillable worksheet pagesRead at your own pace

LET’S TRACE, REASON AND TEST

Using Python with the micro:bit

MakeCode's Python view uses Static Python. The separate micro:bit Python Editor uses MicroPython. Their APIs differ, so code and icon names must match the chosen editor. Keep event-driven MakeCode examples separate from MicroPython polling examples rather than mixing similar-looking commands.

Today’s two goals
  • Switch a MakeCode program between Blocks and MakeCode Python views and identify matching commands.
  • Edit text, image names and button-triggered output while preserving correct case and syntax.
Original PaxaKids illustration for Using Python with the micro:bit. Precise program text and data are supplied in the workbook models.
An original PaxaKids workbook scene. Use the supplied programs and data for precise workbook facts.

Explore the clues

Tap one card to find out more.

Understand the idea

MakeCode's Python view uses Static Python. The separate micro:bit Python Editor uses MicroPython. Their APIs differ, so code and icon names must match the chosen editor. Keep event-driven MakeCode examples separate from MicroPython polling examples rather than mixing similar-looking commands.

Concept to practise: Using Python with the micro:bit.

Work through an example

A MakeCode event handler may use basic.show_string and IconNames. A MicroPython program may use display.scroll and Image after importing microbit. Renaming only the file cannot translate one API into the other.

Try before your workbook

You see basic.show_icon(IconNames.HAPPY) in a MakeCode example. Should you paste it unchanged into a MicroPython program using display.show(Image.HAPPY)? Explain.

Check my readiness thinking

No. Those are different APIs in different environments. Use the names and event or polling structure supported by the selected editor, and test that environment. Do not assume that matching words mean matching code.

Your original programs and learning models

These original PaxaKids program and data models support your workbook. Some examples deliberately contain faults to investigate. Follow their headings and preserve exact code case, punctuation and order. Traces and supplied records are not claims of physical testing.

Read the same event in another view

Our goal: connect Blocks with MakeCode Python, edit exact text and icon names, and test separate A and B events.

This lesson uses MakeCode Python, also called Static Python. Its commands belong to MakeCode. The separate micro:bit Python editor uses MicroPython with different APIs; we will use that environment in the next lesson.

Connect the blocks with the Python

Original block plan
  1. on button A pressed
  2. show string Hello
  3. show icon Happy
Equivalent original Python model
def on_a():
    basic.show_string("Hello")
    basic.show_icon(IconNames.HAPPY)
input.on_button_pressed(Button.A, on_a)

Choose icon names from MakeCode

Choose icon names from MakeCode — original model
IconMakeCode Python member
HeartIconNames.HEART
Small heartIconNames.SMALL_HEART
Happy faceIconNames.HAPPY
Sad faceIconNames.SAD
ORIGINAL EDITED EXAMPLE
def on_a():
    basic.show_string("Sami")
    basic.show_icon(IconNames.SMALL_HEART)
input.on_button_pressed(Button.A, on_a)

Repair three faults in a B handler

FAULTY MAKECODE PYTHON
def on_b():
    basic.show_string(Goodbye)
    basic.show_icon(IconNames.sad)
input.on_button_pressed(Button.A, on_b)

Match the two required event flows

Original event sequences
ButtonTextImage
AHelloHappy
BGoodbyeSad
Paxa the Fox

Try one step with Paxa!

Use the API for the chosen editor. Label paper traces, simulator runs and physical tests accurately; ask a grown-up before connecting equipment. Save personal responses before leaving.

Our Unit 2 learning path
  1. Lesson 2.1: All about software
  2. Lesson 2.2: Introducing the micro:bit
  3. Lesson 2.3: Using Python with the micro:bit
  4. Lesson 2.4: The micro:bit Python environment
  5. Lesson 2.5: Correcting errors using a flowchart
  6. Lesson 2.6: Using sensors in programming
  7. Lesson 2.7: Flowcharts for algorithm planning
  8. Lesson 2.8: Algorithmic solutions and data types
  9. Lesson 2.9: Planning a smart solution
  10. Lesson 2.10: Effective testing
  11. Lesson 2.11: Evaluating a program
  12. Lesson 2.12: Testing accelerometer gestures
  13. Lesson 2.13: Protecting a museum crown
  14. Lesson 2.14: Final project
  15. Lesson 2.15: Evaluation
  16. Lesson 2.16: What can you do?
For grown-ups: using this lesson

Your answers are checked in your browser. Open responses need grown-up review and are shown separately from the automatic score. Check your work, then use “Retry answers to practise” to revisit mistakes while keeping correct responses.

Read one explanation, discuss the model and try the readiness check before the workbook. Choose “Mark lesson finished” when ready. Optional account progress saves lesson position and completion across devices; save personal responses before leaving.

2. Fill in your workbook

Read the teaching and the complete workbook instructions. Choose, write or draw; Answer list offers larger controls. Trace code precisely and distinguish predictions from actual tests. Review designs, explanations and drawings with a grown-up.

Using Python with the micro:bit7 student pages · original artwork

Opening your PDF…

Swipe sideways across the worksheet on a small screen, or use “Answer list” for larger controls.

TAKE YOUR PRACTICE OFFLINE

3. Download the student worksheet

All 7 original A4 student pages, ready for pencil-and-paper practice. Choose Review Answers to check your work on this webpage.

Student worksheet only · PDF · 8.2 MiB · No answer key included

Download worksheet PDF ↓

TRY FIRST, THEN CHECK TOGETHER

Download the student worksheet →

4. Answers & guidance

Finished your try? Open the guide and compare one worksheet at a time. Your own words may be different and still explain the right idea.

Shown on this webpage only. There is no answer-key download, and this guide is left out when printing the page.

Show answers for all 7 worksheets

Worksheet 1

  1. Question 1: Which environment is used for the code in this workbook? MakeCode Python
  2. Question 2: What should stay the same when changing between supported views of one program? its intended behaviour

Worksheet 2

  1. Question 3: Which Python call corresponds to show string? basic.show_string("Hello")
  2. Question 4: Which line connects the handler to button A? input.on_button_pressed(Button.A, on_a)

Worksheet 3

  1. Question 5: Which member names a small heart in MakeCode Python? IconNames.SMALL_HEART

Worksheet 4

  1. Question 6: Which replacement supplies the intended text string? basic.show_string("Goodbye")
  2. Question 7: Which member has the correct case? IconNames.SAD
  3. Question 8: Which registration matches the intended button? input.on_button_pressed(Button.B, on_b)

Worksheet 5

  1. Question 9: What sequence must a B event produce? Goodbye, then Sad
  2. Question 10: Does defining a B handler mean it should run automatically at startup? No; it runs when its registered event occurs.

Worksheet 6

  1. Question 11: Record matching Blocks and Python commands before editing. Save a new copy with different text and a valid icon. Show the edited handler and registration, then test the A event in the simulator. Record expected and actual output, repairs and retests, and explain the exact text/icon changes. Label unrun paper work clearly. Require Blocks/Python comparison, edited text and icon, retained A event and text-before-icon order, correct quotes/colon/indentation/case and matching handler registration. Valid original reference changes Hello/HAPPY to Sami/SMALL_HEART. Other editor-supported icons/text acceptable; choose names from MakeCode, not MicroPython Image table. Actual simulator record required for demonstration, or honestly labelled preparation when unavailable. Save a named edited HEX. Compiler checks for original references do not constitute the learner’s simulator run. Original starter TS source is embedded; learner can select Blocks then Python if imported into text view. Grown-up review; personal evidence is required.

Worksheet 7

  1. Question 12: Show both handlers and registrations. Test A for Hello then Happy, B for Goodbye then Sad, and a second event after the previous sequence finishes. Record expected/actual results, pass/fail and any repair/retest. Explain how both code paths match page E and how the program behaves while waiting without a new event. Require A: basic.show_string("Hello"), then basic.show_icon(IconNames.HAPPY); B: basic.show_string("Goodbye"), then basic.show_icon(IconNames.SAD). Each indented function is registered once with the corresponding Button.A/Button.B and matching handler name. Equivalent names/spacing acceptable; exact output text required by brief. No automatic startup sequence from mere handler definitions. Later A/B events repeat the appropriate sequence; last image may remain while idle. Require saved program and actual simulator evidence or honest unrun label. Tests run sequentially so concurrent event interleaving is outside this lesson’s scope. Original Paxa starter replaces unavailable MicrobitButtonOutputStart.hex. Both final requirements retained across PDF56–57 source boundary. Grown-up review; personal evidence is required.
Back to my workbook ↑

Curriculum & workbook reference

Computing for your homeschool day

Explore Using Python with the micro:bit with this free Grade 7 Computing lesson. Read one idea together, try the fillable workbook and return to review at your own pace. Download the same student worksheet PDF for pencil-and-paper practice.

Fit learning around your family’s day. There is no timer and no sign-up is needed to use the lesson. An optional account saves your lesson position and completion across devices. Workbook responses and drawings stay in this tab; save a copy of your responses before leaving.

Understand your results

Your answers are checked in your browser. Open responses need grown-up review and are shown separately from the automatic score. Check your work, then use “Retry answers to practise” to revisit mistakes while keeping correct responses.

Choose Review Answers after trying the activity. The guide stays on the webpage; the worksheet download contains only the student pages.

For programme background, visit the Cambridge Lower Secondary Computing overview. PaxaKids provides independent original companion practice.

The book pages identify the related teaching topic. The explanations, characters, programs and exercises here are original PaxaKids companion practice. Practical tasks require the appropriate editor and, where applicable, suitable equipment. A design or paper trace is not a verified hardware result. Only completed, reviewed lessons are listed.

Explore the Cambridge Lower Secondary Computing curriculum for programme background. PaxaKids is an independent learning resource.