FBISE, NCP & NBF-aligned resources for Classes 9–12
Browse by Class
Browse by Type
Computer Chapter 3 : Topic 5.3
Populating Lists Using Loops
1 / 17
A Python program initializes an empty list and executes the following code: $\mathbf{numbers = \lbrack\rbrack}$ $\mathbf{for\ i\ in\ range(4):}$ $\mathbf{numbers.append(i)}$ What will be stored in numbers after execution?
Reasoning: $\mathbf{range(4)}$ generates $\mathbf{0}$,$\mathbf{1}$,$\mathbf{2}$,$\mathbf{3}$.
2 / 17
Why is repetition preferred over writing multiple assignment statements when populating large lists in Python programs?
Reasoning: Loops eliminate unnecessary repeated statements.
3 / 17
Which variable changes its value during each iteration of the following loop and controls the sequence of stored values? $\mathbf{for\ i\ in\ range(5):}$ $\mathbf{values.append(i + 2)}$
Reasoning: $\mathbf{i}$ changes every iteration.
4 / 17
A Python program should store the even numbers less than $\mathbf{10}$ in a list. Which code correctly performs this task?
Reasoning: Step size $\mathbf{2}$ generates even numbers.
5 / 17
A programmer accidentally writes the following code: $\mathbf{numbers = \lbrack\rbrack}$ $\mathbf{for\ i\ in\ range(5):}$ $\mathbf{print(i)}$ Why will this program fail?
Reasoning: Python requires proper indentation after loops.
6 / 17
Which sequence of operations correctly translates an algorithm that stores five user-entered values into a list?
Reasoning: Input and append must occur inside the repetition.
7 / 17
Consider the following code: $\mathbf{data = \lbrack\rbrack}$ $\mathbf{for\ i\ in\ range(3):}$ $\mathbf{data.append(i + 1)}$ $\mathbf{print(data)}$ What is the output?
Reasoning: $\mathbf{i + 1}$ produces $\mathbf{1}$,$\mathbf{2}$,$\mathbf{3}$.
8 / 17
Which statement best describes the purpose of the $\mathbf{append()}$ method while translating algorithms into Python?
Reasoning: $\mathbf{append()}$ inserts a single element at the end.
9 / 17
A programmer wants to generate multiples of $\mathbf{3}$ up to $\mathbf{15}$ using repetition. Which expression should be appended?
Reasoning: Multiplying by $\mathbf{3}$ generates multiples.
10 / 17
After executing the following program, what is stored in the list? $\mathbf{items = \lbrack\rbrack}$ $\mathbf{for\ i\ in\ range(1,5):}$ $\mathbf{items.append(i*2)}$
Reasoning: Values are doubled before storing.
11 / 17
Which Python construct is primarily responsible for implementing repetition while translating an algorithm into code?
Reasoning: Loops perform repeated execution.
12 / 17
A student forgets to initialize an empty list before using append(). What is the most likely result?
Reasoning: The variable must exist before using its methods.
13 / 17
A loop executes six times, appending the values of $\mathbf{i}$. How many elements will be present in the list after completion?
Reasoning: One element is added per iteration.
14 / 17
Which code correctly stores the numbers from $\mathbf{10}$ to $\mathbf{14}$ in a list?
Reasoning: $\mathbf{range(10,15)}$ generates $\mathbf{10–14}$.
15 / 17
Why is a variable commonly used inside a repetition structure when populating a list?
Reasoning: The loop variable provides changing values.
16 / 17
Which algorithm is best represented by the following Python code? $\mathbf{numbers = \lbrack\rbrack}$ $\mathbf{for\ i\ in\ range(5):}$ $\mathbf{numbers.append(i*i)}$
Reasoning: $\mathbf{i*i}$ calculates squares.
17 / 17
A programmer needs to store the first ten positive integers in a list. Which loop is most appropriate?
Reasoning: Positive integers begin from $\mathbf{1}$.
Your score is
Restart quiz