Choose the correct output of the following Python program snippet: D = 11 B, E…

2026

Choose the correct output of the following Python program snippet:
D = 11
B, E = 0, 1
while D > 0:
R = D % 2
D //= 2
B += R * E
E *= 10
print(B)

  1. A.

    1011

  2. B.

    1101

  3. C.

    1001

  4. D.

    1100

Attempted by 493 students.

Show answer & explanation

Correct answer: A

The code converts a decimal number (11) into its binary representation.

Step-by-step:
D = 11
Iteration 1: R = 11 % 2 = 1 → B = 1, E = 10, D = 5
Iteration 2: R = 5 % 2 = 1 → B = 11, E = 100, D = 2
Iteration 3: R = 2 % 2 = 0 → B = 11, E = 1000, D = 1
Iteration 4: R = 1 % 2 = 1 → B = 1011, E = 10000, D = 0

Loop stops.

Final value of B = 1011

Correct answer: Option A (1011)

Explore the full course: Rssb Senior Computer Instructor