As with any written programming language, you occasionally make mistakes and run into errors that you will need to fix in order for your program to run.
The micro:bit Python Editor shows you the errors in your code, so you know what you need to fix before flashing your code to the micro:bit.
Errors are indicated in the margin by a red dot or grey square. They are also indicated by using a red triangle or a red wavy underline:
Type of error | Why does this error occur? | Example of how this error is indicated |
Syntax error | Syntax errors occur when you type something wrong; you could have missed part of a statement or misspelt it. | Statements must be separated by newlines or semicolons |
Indentation error | Indentation errors occur when you make a mistake with the code structure. | Expected indented block |
Type error | This happens when you put the wrong type of data in the wrong place in your code, such as trying to add a string to an integer | Operertor "x" is not supported for type. |
Name error | A name error occurs when you try to use a variable or function that has not been defined yet. | "a" is not defined |
Logic error | This means that there is nothing wrong with the code regarding indentation and syntax, but the logic of the code or algorithm is incorrect | |
Unreachable code | This means that the program you are running never reaches the code indicated by the error |