nerdexam
Python_Institute

PCEP-30-02 · Question #340

What is the expected output of the following code? counter = 84 // 2 if counter < 0: print("") elif counter >- 42: print("") else: print("")

The correct answer is B. **. Option B (`) is correct because 84 // 2 evaluates to 42 (floor/integer division), so counter = 42. The first condition counter < 0 is false (42 is positive), but the elif condition counter > -42 reads as "greater than negative 42" - and 42 is indeed greater than -42, so is…

Question

What is the expected output of the following code? counter = 84 // 2 if counter < 0: print("") elif counter >- 42: print("") else: print("")

Options

  • A
  • B**
  • C
  • DThe code produces no output.

How the community answered

(23 responses)
  • A
    9% (2)
  • B
    87% (20)
  • D
    4% (1)

Explanation

Option B (**) is correct because 84 // 2 evaluates to 42 (floor/integer division), so counter = 42. The first condition counter < 0 is false (42 is positive), but the elif condition counter > -42 reads as "greater than negative 42" - and 42 is indeed greater than -42, so ** is printed.

Why the distractors are wrong:

  • A (*) requires counter < 0, but 42 is positive, so the if branch is skipped entirely.
  • C (***) requires both the if and elif to be false, but since elif is true, the else block never runs.
  • D (no output) is impossible here - in an if/elif/else chain, exactly one branch always executes.

Memory tip: Watch for the >- operator - it's a common visual trick. It is not a special operator; it's simply > followed by a negative sign (> -42). Always read spacing carefully around comparison operators in exam questions.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice