Text input and output

If you’re using a Chrome or Edge web browser, you can access a serial console here in the editor. A serial console allows you to print information from your micro:bit on your computer screen, and use your computer’s keyboard to input information into your Python programs.

Open the serial console

../_images/show-serial.png

Plug your micro:bit into your computer’s USB socket, click on ‘connect’ then pair your micro:bit. When you flash a Python program to your micro:bit, you can access the serial console by clicking ‘Show serial’.

Keyboard input

You can interact with Python micro:bit programs by entering text on your computer keyboard:

name = input('What is your name? ')
print('Hello', name)

This example asks your name. When you click in the serial console, type your name and press enter, it will greet you.

REPL

You can use the serial console to type and execute Python commands directly on your micro:bit.

../_images/serial-output.png

Exercises

  1. Try to use the mathematical operations to divide 100 by 7 and then round off using floor, but instead of showing to the LED screen, print it on the serial console.
  2. Get a number from the user between 1 and 100 and print out all the factors of that number.