Skip to content

Python beating heart

Lesson 2 of 6

Python

9-12 yrs, 11-14 yrs

Create an animation to learn about sequence and simple loops.

Key learning:

  • I know why the sequence of instructions is important.
  • I can write instructions in Python to create a forever (infinite) loop.
  • I can give the micro:bit instructions in text-based code to make a beating heart animation.

Computational thinking:

Algorithms

Digital arts:

Animation

Programming:

Iteration

Sequence

Text-based programming

Lesson plan preview

Slides preview

Student handouts

Completed lesson code

This provides an example of the code created during this lesson.

1# imports go at the top
2from microbit import *
3
4
5# Code in a 'while True:' loop repeats forever
6while True:
7    display.show(Image.HEART)
8    sleep(500)
9    display.show(Image.HEART_SMALL)
10    sleep(500)

You may also be interested in

Introduces our Python Editor that helps learners to write code for the BBC micro:bit. We will highlight all the great features in our editor that support you and your learners to code the micro:bit successfully using Python.

A sequence of lessons that provide a pathway through six projects, ideal for getting started with the micro:bit. Students develop their use of some core computing concepts by coding and making practical projects including step counters, nightlights, and games.

Seven lessons introducing AI in general and unpacking what students already know about sorting data, before getting hands-on, creating, testing and improving their own machine learning models to be used as new inputs in code on the micro:bit.