3. Indentation Errors
Indentation needs to be consistent, since python uses indentation to block code together.
Indentation is used with selection (if…elif…else) and iteration (while, for) to group the code together after the colon.
3.1. Missing Indentation after if statement
The correctly indented code is below:
from microbit import *
if button_a.is_pressed():
display.scroll('A')
In the code below,
display.scroll('A')
should be indented, but is not.from microbit import *
if button_a.is_pressed():
display.scroll('A')
The error check shows that an indented block was expected to follow the if statement.
3.2. else statement indented by mistake
The correctly indented code is below:
from microbit import *
if button_a.is_pressed():
display.scroll('A')
else:
display.show(1)
In the code below,
else
should not be indented, but it is.from microbit import *
if button_a.is_pressed():
display.scroll('A')
else:
display.show(1)
The error message doesn’t identify specifically that
else
should not be indented.3.3. for-loop not indented
The correctly indented code is below:
from microbit import *
for num in range(5):
display.scroll(num)
In the code below,
display.scroll(num)
should be indented, but it is not.from microbit import *
for num in range(5):
display.scroll(num)
The error check shows a syntax error and an expected indentation after the for statement.