Back to questions
JuniorTheoryCommon
What does the program print?
n = 0
sign = "plus" if n > 0 else "minus" if n < 0 else "zero"
print(sign)zero
- Expecting
minus, as ifelseended the expression: the part afterelseis itself"minus" if n < 0 else "zero", and0 < 0is false. - Expecting
plus, as if zero counted as positive:0 > 0is false, so the first value is skipped and the check moves on ton < 0.
- How would you write the same choice with
if,elifandelse? - What does the program print when
n = -3?