FBISE, NCP & NBF-aligned resources for Classes 9–12
Browse by Class
Browse by Type
Computer Chapter 3 : Topic 5.4
Searching for Elements in Lists
1 / 15
A student writes a Python program to search for the number $\mathbf{15}$ in the list $\mathbf{numbers = \lbrack 8,12,15,20\rbrack}$. Which code correctly implements the searching algorithm?
Reasoning: The algorithm checks every element using repetition until the desired value is found.
2 / 15
A Python program searches a list using the following code. What will be displayed? $\mathbf{values =}\left\lbrack \mathbf{4,8,12,16} \right\rbrack$ $\mathbf{target = 12}$ $\mathbf{for\ x\ in\ values:}$ $\mathbf{if\ x = = target:}$ $\mathbf{print("Found")}$
Reasoning: The value $\mathbf{12}$ exists in the list, so the condition becomes true.
3 / 15
Consider the following Python program used for searching a value in a list. What will be the final output? $\mathbf{data = \lbrack 2,4,6\rbrack}$ $\mathbf{target = 5}$ $\mathbf{found = False}$ $\mathbf{for\ x\ in\ data:}$ $\mathbf{if\ x = = target:}$ $\mathbf{found = True}$ $\mathbf{print(found)}$
Reasoning: Since $\mathbf{5}$ is not present, $\mathbf{found}$ remains $\mathbf{False}$.
4 / 15
A programmer accidentally writes the following condition while searching a list: $\mathbf{if\ x = ta}\mathbf{rget:}$ Why will this statement fail?
Reasoning: Python requires $= =$ for comparison, not $=$.
5 / 15
Consider the following Python code used for searching: $\mathbf{numbers = \lbrack 5,9,13\rbrack}$ $\mathbf{for\ n\ in\ numbers:}$ $\mathbf{if\ n = = 9:}$ $\mathbf{print}\left( \mathbf{"Found"} \right)$ $\mathbf{break}$ What is the main advantage of using $\mathbf{break}$ in this program?
Reasoning: $\mathbf{break}$ improves efficiency by ending the search immediately.
6 / 15
A student replaces the loop with the following statement while searching: $\mathbf{print(numbers\lbrack 0\rbrack = = target)}$ Why does this statement fail to implement the intended searching algorithm correctly?
Reasoning: A proper search examines every element until the target is found.
7 / 15
Which Python structure repeats comparisons when searching for a target inside lists?
Reasoning: A $\mathbf{for}$ loop can examine list elements repeatedly until the required element is found.
8 / 15
Why should a search target be stored in a variable before checking elements inside list?
Reasoning: A variable stores the required value so each list element can be compared against the same target.
9 / 15
Why is repetition necessary when a program must examine several list elements before locating the required target value during search?
Reasoning: Repetition allows the same comparison operation to be performed on successive elements of the list.
10 / 15
Which variable value can initially represent that the searched element is absent?
Reasoning: $\mathbf{False}$ indicates that no matching element has been found before the search begins.
11 / 15
What is the purpose of comparing each current list item with the stored search target?
Reasoning: Comparing the current item with the target determines whether the required element has been found.
12 / 15
Which Python statement can stop a loop immediately after the program finds the required element in a list during searching?
Reasoning: $\mathbf{break}$ immediately terminates the loop when the target is found, avoiding unnecessary further comparisons.
13 / 15
Which step should occur first in a program performing sequential list searching?
Reasoning: The program needs a list and target value before it can begin performing comparisons.
14 / 15
If every list element is checked without a match, what should the program finally report?
Reasoning: When all elements have been examined without a successful comparison, the target is not present in the list.
15 / 15
Why is an index variable useful when a program must correctly report the exact position of a found list element?
Reasoning: An index keeps track of an element’s position, allowing the program to report where the target was found.
Your score is
Restart quiz