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

The following Python function takes an integer x as input and prints a character: Which...

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

The following Python function takes an integer x as input and prints a character:

def describe(x):
    if x == 0:
        if x > 0:
            print('A')
        else:
            print('B')
    else:
        if x > 0:
            print('C')
        else:
            print('D')

Which character will never be printed?

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

The outer condition checks if x == 0. When this is true, the inner condition if x > 0 can never be true because x is already 0, so the branch printing 'A' is unreachable. The other branches ('B', 'C', 'D') are all reachable under different values of x (x == 0 with fallback for 'B', x > 0 for 'C', x < 0 for 'D').

Step-by-step Derivation:
Trace through all possible cases:

  1. x == 0: Enters outer if block. Inner condition x > 0 is false (0 is not > 0), so prints 'B'. Path to 'A' is unreachable.
  2. x > 0: Enters outer else block. Inner condition x > 0 is true, so prints 'C'.
  3. x < 0: Enters outer else block. Inner condition x > 0 is false, so prints 'D'.

Conclusion: 'A' is the only character that can never be printed because the condition x == 0 AND x > 0 is logically impossible.