OA. free
Free
Accenture Core Computer Science Core Computer Science Medium

Consider the Python function: Which character will never be printed for any integer n?

Accenture technical mcq question, verified with a worked answer. Free to practise - no sign-up.

Consider the Python function:

def describe(n):
    if n > 0:
        if n < 0:
            print('X')
        else:
            print('Y')
    else:
        print('Z')

Which character will never be printed for any integer n?

Choose one option.
Show answer & explanation
Answer: A. 'X'

The character 'X' is unreachable because it requires n > 0 AND n < 0 to be true simultaneously, which is logically impossible. For any integer n, either 'Y' (when n > 0), 'Z' (when n ≤ 0) will be printed, but never 'X'.

Step-by-step Derivation:
Trace the control flow:

  1. For n > 0: Enter first if block → Check inner condition (n < 0) → Since n > 0, n cannot be < 0 → Execute else block → Print 'Y' ✓
  2. For n ≤ 0: Skip first if block → Execute else block → Print 'Z' ✓
  3. For 'X' to print: Need n > 0 AND n < 0 simultaneously → Impossible for any real number

Therefore, 'X' is unreachable code.