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

Computer 11th

Computer 11th Chap 3 : Topic 7.4

/14

Report a question

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Your score is

0%