Choose the correct output of the following Python program snippet: A, B = 95,…

2026

Choose the correct output of the following Python program snippet:

A, B = 95, 65

while A != B:

if A > B:

A -= B

else:

B -= A

print(A)

  1. A.

    1

  2. B.

    5

  3. C.

    15

  4. D.

    30

Attempted by 163 students.

Show answer & explanation

Correct answer: B

This program uses the subtraction-based method to find the GCD (Greatest Common Divisor).

Initial values:
A = 95, B = 65

Step 1: A > B → A = 95 - 65 = 30
Now A = 30, B = 65

Step 2: B > A → B = 65 - 30 = 35
Now A = 30, B = 35

Step 3: B > A → B = 35 - 30 = 5
Now A = 30, B = 5

Step 4: A > B → A = 30 - 5 = 25
Step 5: A = 25 - 5 = 20
Step 6: A = 20 - 5 = 15
Step 7: A = 15 - 5 = 10
Step 8: A = 10 - 5 = 5

Now A = 5, B = 5 → loop stops

print(A) → 5

Correct answer: Option B (5)

Explore the full course: Rssb Senior Computer Instructor