Quiz: Python Basics — Programs, Variables, Data Types, and Operators
Test your understanding of Python programs, variables, data types, and operators with these questions.
1. What does a computer program tell the computer to do?
- Store files on the hard drive
- Follow a list of instructions step by step
- Connect to the internet automatically
- Draw pictures on the screen
Show Answer
The correct answer is B. A computer program is a list of instructions for a computer to follow, similar to a recipe that tells a chef exactly what to do step by step. When you load a program onto your Pico, the microcontroller reads your source code and carries out each instruction in order.
Concept Tested: Computer Program
2. Which of the following is the best name for a variable that stores how many LEDs you have?
xnnum_ledsvariable1
Show Answer
The correct answer is C. Variable names should describe what they hold. num_leds tells anyone reading the code exactly what the variable stores — the number of LEDs. Short names like x or n tell you nothing, and generic names like variable1 are equally unhelpful.
Concept Tested: Variable
3. What data type is the value "Hello, Pico!"?
- Integer
- Boolean
- Float
- String
Show Answer
The correct answer is D. A string is any sequence of characters placed inside quotation marks. The quotation marks around "Hello, Pico!" are the key clue — they make this value a string even though it contains letters, a comma, and a space.
Concept Tested: String
4. What value does the boolean variable led_is_on = False hold?
- The number zero
- The text "False"
- The logical value False (off/no)
- An empty string
Show Answer
The correct answer is C. A boolean holds exactly one of two logical values: True or False. It is not the number 0 or the text "False" — it is its own special data type used to represent on/off, yes/no, or true/false conditions. Notice that False must be spelled with a capital F.
Concept Tested: Boolean
5. What symbol starts a comment in Python?
///*#--
Show Answer
The correct answer is C. In Python, the hash symbol # marks the start of a comment. Python ignores everything after # on that line. Comments explain your code to human readers without affecting how the program runs.
Concept Tested: Comment in Code
6. Which line of code correctly prints the text MicroPython to the screen?
print MicroPythonprint("MicroPython")display("MicroPython")print[MicroPython]
Show Answer
The correct answer is B. The print() function requires parentheses after it, and the text to display must be placed inside quotation marks within those parentheses. Option A is missing the parentheses. Option C uses the wrong function name. Option D uses square brackets instead of parentheses.
Concept Tested: Print Statement
7. What is the result of 15 % 4 in Python?
- 3.75
- 3
- 60
- 11
Show Answer
The correct answer is B. The % operator (modulo) returns the remainder after division. 15 ÷ 4 = 3 with a remainder of 3. Think of it like sharing 15 pizza slices among 4 people — each person gets 3 slices, and 3 slices are left over. The remainder is 3, not the quotient.
Concept Tested: Arithmetic Operators
8. What is the difference between = and == in Python?
- They do the same thing — both compare values
=stores a value in a variable;==checks if two values are equal==stores a value in a variable;=checks if two values are equal=only works with numbers;==works with all types
Show Answer
The correct answer is B. The single = is the assignment operator — it stores a value in a variable (e.g., age = 12). The double == is the comparison operator — it checks whether two values are equal and produces True or False (e.g., age == 12 produces True). Mixing them up is one of the most common beginner mistakes.
Concept Tested: Comparison Operators / Assignment Operators
9. After running count = 5 and then count += 3, what value does count hold?
- 5
- 3
- 53
- 8
Show Answer
The correct answer is D. The += shortcut means "add to the current value and store the result." count += 3 is the same as writing count = count + 3, so 5 + 3 = 8. The original value of 5 is replaced by 8.
Concept Tested: Assignment Operators
10. What data type would you choose to store the voltage reading 3.3 from a Pico pin?
- Boolean
- String
- Float
- Integer
Show Answer
The correct answer is C. A float stores numbers that have a decimal point. Since 3.3 has a decimal part, it must be stored as a float. An integer can only hold whole numbers like 3, not 3.3. A string would store it as text, making math impossible, and a boolean can only be True or False.
Concept Tested: Float / Data Type