Q.Check whether a number is positive, negative, or zero.
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Positive / negative / zero are three mutually exclusive cases — the textbook use of an if–elif–else ladder, where exactly one branch runs.
The idea. A number's sign has exactly three possibilities, and they cannot overlap. Multi-way selection like this is what if–elif–else exists for: test number > 0 first, test number < 0 only if that failed, and let else claim the single remaining possibility (zero) without any test.
Program
number = int(input("Enter a number: "))
if number > 0:
print("The number is positive")
elif number < 0:
print("The number is negative")
else:
print("The number is zero")
Sample runs
Enter a number: 12
The number is positive
Enter a number: -7
The number is negative
Enter a number: 0
The number is zero
Why else needs no condition: after number > 0 and number < 0 have both failed, the only value left is 0 — the ladder's structure itself proves it, so a third comparison would be redundant.
| Input | number > 0 | number < 0 | Branch taken |
| --- | --- | --- | --- | …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.