1. Micro:bit MicroPython Basics Quiz

1.1. Question 1

Which of the following is the correct statement to import the Micro:bit library according to the provided documentation?

Correct. This uses lowercase letters, proper spacing, and includes the asterisk.
Incorrect. This contains a syntax layout issue because it is missing a space before the asterisk.
Incorrect. The library name 'microbit' is misspelled as 'microbot'.
Incorrect. This completely omits the required 'import' keyword.

1.2. Question 2

According to the PEP 8 guide mentioned in the text, how many blank lines should follow a basic library import to separate it from the rest of the code?

Correct. The PEP 8 standard specifies placing exactly one blank line after standard library imports.
Incorrect. Leaving no blank line compresses the code layout.
Incorrect. Two blank lines are typically reserved before or after top-level class or function definitions.
Incorrect. Three blank lines are excessive and deviate from standard Python spacing conventions.

1.3. Question 3

What happens when you use the statement ‘while True:’ in Python?

Correct. Passing the boolean literal True directly causes the loop to run forever.
Incorrect. A while loop keeps executing as long as its condition remains true.
Incorrect. This is fully valid Python syntax and compiles correctly.
Incorrect. The boolean condition True does not inspect hardware states automatically.

1.4. Question 4

Which of the following demonstrates a valid beginning line of an infinite loop in Python?

Correct. This correctly utilizes a lowercase 'while', a capitalized 'True', and ends with a colon.
Incorrect. Python is case-sensitive, so the boolean literal must begin with an uppercase 'T'.
Incorrect. The keyword 'while' must be entirely lowercase; capitalizing the 'W' causes a syntax error.
Incorrect. A compound statement block header like a while loop requires a colon at the end.

1.5. Question 5

When importing a module using ‘from microbit import *’, how does it affect the syntax prefix for functions like display.scroll()?

Correct. Using a wildcard import allows shorter forms like display.scroll().
Incorrect. The asterisk is an import syntax operator and cannot be appended to object reference paths.
Incorrect. The long prefix is used when the module is imported via 'import microbit'.
Incorrect. An alias like 'mb' is only available if explicitly defined using an 'as' clause.

1.6. Question 6

If you want to pause your program execution for exactly 2 seconds, which code statement should you use?

Correct. The sleep function takes an argument in milliseconds, and 2000 milliseconds equals 2 seconds.
Incorrect. Passing 2 will only pause the script for 2 milliseconds.
Incorrect. This would result in a pause of 20 milliseconds.
Incorrect. Decimal numbers are valid, but 0.2 represents less than one millisecond, not two seconds.

1.7. Question 7

What parameter unit is accepted by the sleep() function in MicroPython?

Correct. The documentation specifies that sleep values represent time intervals measured in milliseconds.
Incorrect. Standard Python modules like 'time' use seconds, but the Micro:bit's direct sleep function uses milliseconds.
Incorrect. Minutes are far too large of a base unit for precise hardware runtime control setups.
Incorrect. Microseconds are smaller than milliseconds and are not the primary unit for this basic sleep call.

1.8. Question 8

How are lines grouped inside a while-loop structure to show they belong inside the loop block?

Correct. Python relies on clean whitespace indentation blocks to group statements together.
Incorrect. Curly braces are used to denote blocks in languages like C or Java, but not in Python.
Incorrect. Semicolons are optional line terminators in Python and do not define hierarchical structural containment.
Incorrect. While loops can stretch across multiple lines, and layout structures demand independent row indentation.

1.9. Question 9

If you need a secondary pause to last for a quarter of a second, what value should be passed to the sleep statement?

Correct. Since 1000 milliseconds equals one second, a quarter of that duration is exactly 250 milliseconds.
Incorrect. Passing 0.25 pauses for a fraction of one millisecond.
Incorrect. This would result in a pause lasting 25 milliseconds, which is only 1/40th of a second.
Incorrect. This represents two and a half milliseconds rather than a quarter of a whole second.

1.10. Question 10

According to standard code layout principles, when are 2 blank lines used after importing modules instead of 1?

Correct. The documentation points out that advanced structures like classes require two surrounding blank spaces.
Incorrect. Spacing styles are determined by language readability rules, completely independent of hardware version iterations.
Incorrect. Whitespace changes formatting appearance but does not alter logical loop stopping conditions.
Incorrect. A single blank line is the default setup for normal procedural statements following a wildcard import.