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
Options
- A
- B**
- C
- DThe code produces no output.
How the community answered
(23 responses)- A9% (2)
- B87% (20)
- D4% (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 (
*) requirescounter < 0, but 42 is positive, so theifbranch is skipped entirely. - C (
***) requires both theifandelifto be false, but sinceelifis true, theelseblock never runs. - D (no output) is impossible here - in an
if/elif/elsechain, 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.