FBISE, NCP & NBF-aligned resources for Classes 9–12
Browse by Class
Browse by Type
Computer Chapter 3 : Topic 7.4
Debuggers and Breakpoints
1 / 14
A programmer gets an incorrect total; where should a breakpoint be placed to inspect values before addition? $\mathbf{price = 500\ \ \ \ \ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{quantity = 4\ \ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{total = price*quantity\ \ \ \#\ Line\ 3}$ $\mathbf{print(total)\ \ \ \ \ \ \ \ \ \#\ Line\ 4}$
Reasoning: A breakpoint before Line $\mathbf{3}$ allows the programmer to inspect $\mathbf{price}$ and $\mathbf{quantity}$ before the calculation.
2 / 14
The following program produces a wrong average; which breakpoint best helps inspect values before calculating it? $\mathbf{total = 450\ \ \ \ \ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{subjects = 5\ \ \ \ \ \ \ \ \ \#\ Li}\mathbf{ne\ 2}$ $\mathbf{average = total/subjects\ \ \ \#\ Line\ 3}$ $\mathbf{print(average)\ \ \ \ \ \ \ \#\ Line\ 4}$
Reasoning: Stopping before Line $\mathbf{3}$ lets the programmer inspect both variables used in the average calculation.
3 / 14
A discount result is incorrect; where should execution stop to examine variables before applying the discount formula? $\mathbf{price = 2000\ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{discount = 10\ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{reduction = price*discount/100\ \ \ \#\ Line\ 3}$ $\mathbf{final\_ price = price - reduction\ \ \ \ \ \ \#\ Line\ 4}$ $\mathbf{print(final\_ price)\ \ \ \ \ \ \ \#\ Line\ 5}$
Reasoning: Line $\mathbf{3}$ uses $\mathbf{price}$ and $\mathbf{discount}$, so stopping there allows both input values to be inspected first.
4 / 14
The loop gives an unexpected total; where should a breakpoint be placed to inspect each addition? $\mathbf{numbers = \lbrack 10,\ 20,\ 30\rbrack\ \ \ \ \#\ Line\ 1}$ $\mathbf{total = 0\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{for\ num\ in\ numbers:\ \ \ \ \ \ \ \#\ Line\ 3}$ $\mathbf{total = total + num\ \ \ \#\ Line\ 4}$ $\mathbf{print(total)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 5}$
Reasoning: A breakpoint at Line $\mathbf{4}$ allows $\mathbf{num}$ and the current $\mathbf{total}$ to be examined during every iteration.
5 / 14
A function returns an unexpected product; which breakpoint allows inspection of parameters before multiplication occurs? $\mathbf{def\ multiply(a,\ b):\ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{result = a*b\ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{return\ result\ \ \ \ \ \ \ \ \#\ Line\ 3}$ $\mathbf{answer = multiply(5,\ 6)\ \ \#\ Line\ 4}$
Reasoning: Stopping at Line $\mathbf{2}$ allows the values of parameters $\mathbf{a}$ and $\mathbf{b}$ to be checked before multiplication.
6 / 14
The wrong grade is displayed; where should execution pause to inspect marks before evaluating the condition? $\mathbf{mar}\mathbf{ks = 72\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{if\ marks} > = \mathbf{80:\ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{grade = "A"\ \ \ \ \ \ \#\ Line\ 3}$ $\mathbf{else:}$ $\mathbf{grade = "B"\ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 4}$ $\mathbf{print(grade)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 5}$
Reasoning: The condition depends on $\mathbf{marks}$, so Line $\mathbf{2}$ is suitable for inspecting its value before comparison.
7 / 14
A list element seems incorrect; which breakpoint best allows inspection of the index before list access? $\mathbf{students = \lbrack"Ali",\ "Sara",\ "Ahmed"\rbrack\ \ \ \#\ Line\ 1}$ $\mathbf{index = 2\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{name = students\lbrack index\rbrack\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 3}$ $\mathbf{print(name)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 4}$
Reasoning: At Line $\mathbf{3}$, both the list and $\mathbf{index}$ can be inspected before the element is accessed.
8 / 14
A $\mathbf{while}$ loop behaves unexpectedly; where should a breakpoint help inspect the counter during every iteration? $\mathbf{count = 1\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{while\ count} < = \mathbf{5:\ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{print(count)\ \ \ \ \ \ \ \ \ \#\ Line\ 3}$ $\mathbf{count + = 1\ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 4}$ $\mathbf{print("Finished")\ \ \ \ \ \ \ \ \#\ Line\ 5}$
Reasoning: A breakpoint at Line $\mathbf{2}$ lets the programmer inspect $\mathbf{cou}\mathbf{nt}$ before each loop-condition evaluation.
9 / 14
Division causes an error; which breakpoint should inspect the divisor immediately before the risky calculation? $\mathbf{total = 100\ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{count = 0\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{average = total\ /\ count\ \ \#\ Line\ 3}$ $\mathbf{print(average)\ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 4}$
Reasoning: Stopping before Line $\mathbf{3}$ reveals that $\mathbf{count}$ equals zero before division occurs.
10 / 14
The maximum value found is unexpected; where should execution pause to inspect values before comparison? $\mathbf{numbers = \lbrack 12,\ 35,\ 18\rbrack\ \ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{maximum = numbers\lbrack 0\rbrack\ \ \ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{for\ num\ in\ numbers:\ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 3}$ $\mathbf{if\ num} > \mathbf{maximum:\ \ \ \ \ \ \ \ \ \#\ Line\ 4}$ $\mathbf{maximum = num\ \ \ \ \ \ \ \ \ \#\ Line\ 5}$ $\mathbf{print(maximum)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 6}$
Reasoning: Line $\mathbf{4}$ allows $\mathbf{num}$ and $\mathbf{maximum}$ to be inspected before deciding whether $\mathbf{maximum}$ should change.
11 / 14
A factorial program produces an incorrect result; which breakpoint best tracks changing values inside the loop? $\mathbf{n = 5\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{factorial = 1\ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{for\ i\ in\ range(1,\ n + 1):\ \ \#\ Line\ 3}$ $\mathbf{factorial* = i\ \ \ \ \ \ \ \#\ Line\ 4}$ $\mathbf{print(factorial)\ \ \ \ \ \ \ \ \ \#\ Line\ 5}$
Reasoning: The breakpoint at Line $\mathbf{4}$ allows $\mathbf{i}$ and $\mathbf{factorial}$ to be observed during every multiplication.
12 / 14
The calculated salary is wrong; where should a breakpoint inspect both values before computing final salary? $\mathbf{basic = 50000\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{bonus = 5000\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{salary = basic + bonus\ \ \ \ \ \ \#\ Line\ 3}$ $\mathbf{tax = salary*0.10\ \ \ \ \ \ \ \ \ \#\ Line\ 4}$ $\mathbf{final\_ salary = salary - tax\ \#\ Line\ 5}$
Reasoning: If the final salary is wrong, stopping at Line $\mathbf{5}$ allows $\mathbf{salary}$ and $\mathbf{tax}$ to be inspected before subtraction.
13 / 14
A function returns the wrong area; where should execution stop to inspect radius before calculation? $\mathbf{def\ circle\_ area(radius):\ \ \ \ \ \ \ \ \ \ \#\ Line\ 1}$ $\mathbf{area = 3.14*radius*radius\ \#\ Line\ 2}$ $\mathbf{return\ area\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 3}$ $\mathbf{result = circle\_ area(5)\ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 4}$ $\mathbf{print(result)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 5}$
Reasoning: Stopping at Line $\mathbf{2}$ allows the parameter $\mathbf{radius}$ to be inspected before the area formula executes.
14 / 14
The program selects an incorrect username; which breakpoint should inspect entered data before comparison occurs? $\mathbf{username = input("Username:\ ")\ \ \ \ \#\ Line\ 1}$ $\mathbf{saved\_ name = "admin"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\ Line\ 2}$ $\mathbf{if\ username = = saved\_ name:\ \ \ \ \ \ \ \ \#\ Line\ 3}$ $\mathbf{print("Access\ granted")\ \ \ \ \ \ \ \#\ Line\ 4}$ $\mathbf{else:}$ $\mathbf{print("Access\ denied")\ \ \ \ \ \ \ \ \#\ Line\ 5}$
Reasoning: Before Line $\mathbf{3}$ executes, the programmer can inspect both $\mathbf{username}$ and $\mathbf{saved\_ name}$ to identify mismatched values.
Your score is
Restart quiz