Python program: Positive, negative or zero
Classify numbers as positive, negative or zero.
The code
for n in [5, -2.5, 0]: if n > 0: kind = "positive" elif n < 0: kind = "negative" else: kind = "zero" print(n, "is", kind)
Output
5 is positive -2.5 is negative 0 is zero
How it works
Three cases need if, elif and else. Exactly one branch runs for each number.
Learn the ideas behind it in the free lesson Making Decisions.