FBISE, NCP & NBF-aligned resources for Classes 9–12

Computer 11th

Computer 11th Chap 3 : Topic 5.4

/15

Report a question

You cannot submit an empty report. Please add some details.

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?

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")}$

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)}$

4 / 15

A programmer accidentally writes the following condition while searching a list:
$\mathbf{if\ x = ta}\mathbf{rget:}$
Why will this statement fail?

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?

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?

7 / 15

Which Python structure repeats comparisons when searching for a target inside lists?

8 / 15

Why should a search target be stored in a variable before checking elements inside list?

9 / 15

Why is repetition necessary when a program must examine several list elements before locating the required target value during search?

10 / 15

Which variable value can initially represent that the searched element is absent?

11 / 15

What is the purpose of comparing each current list item with the stored search target?

12 / 15

Which Python statement can stop a loop immediately after the program finds the required element in a list during searching?

13 / 15

Which step should occur first in a program performing sequential list searching?

14 / 15

If every list element is checked without a match, what should the program finally report?

15 / 15

Why is an index variable useful when a program must correctly report the exact position of a found list element?

Your score is

0%