1. Microbit library

1.1. Import the microbit library

The microbit requires a library or module for it to work.
To use that library, always start the microbit code in Mu editor with:
from microbit import *

Questions

Describe the error in attempting to import the microbit library.

  1. from microbit import

  2. from microbit import*

  3. from microbot import *

  4. from microbit *

from microbit import error

# missing * at end
from microbit import *

from microbit import* error

# missing space before *
from microbit import *

from microbot import * error

# microbit misspelt
from microbit import *

from microbit * error

# missing import before *
from microbit import *

1.2. Blank Lines

All microbit libraries or modules are imported at the top of the file.
Place 1 blank line following the the importing of libraries to separate those lines from the rest of the code.
The PEP8 guide states that there should be 1 blank line after the library imports. In more advanced code, classes and definitions should have 2 blank lines before and after them. So 2 blank lines after importing is used when followed by a class or definition.
For advanced users, see full PEP 8 guide at: https://www.python.org/dev/peps/pep-0008/

Note

Surround top-level function and class definitions with two blank lines.
Method definitions inside a class are surrounded by a single blank line.
Extra blank lines may be used (sparingly) to separate groups of related functions.
Use blank lines in functions, sparingly, to indicate logical sections.

Questions

  1. How could the layout of the code be improved?

from microbit import *


while True:
    display.scroll(char, delay=80)
  1. How could the layout of the code be improved?

from microbit import *
num = 12
while True:
    display.scroll(num, delay=80)

How could the layout of the code be improved? Remove the extra blank line after the library import.

from microbit import *

while True:
    display.scroll(char, delay=80)

How could the layout of the code be improved? Add a blank line after the library import.

from microbit import *

num = 12
while True:
    display.scroll(num, delay=80)

For other forms of importing libraries see:
Importing using from module_name import * is not recommended for general python use.
It is used here to keep the microbit syntax shorter.
On other websites, references to the microbit library syntax may have microbit. before the function or method.
e.g microbit.display.scroll("Hi")
This is because it assumes that the microbit library has been imported using import microbit.
When importing the microbit library using: from microbit import *, the microbit. prefix is omitted.
e.g This allows the shorter form, display.scroll("Hi"), instead of the longer form, microbit.display.scroll("Hi").

1.3. Micropython API

The main reference for using micropython with the microbit is at:
For new microbits (v2) from 2022 see: