PythonMastery

Check if a number is positive, negative or zero in Python

Read a number and print whether it is positive, negative or zero, using an if / elif / else chain.

Three possible answers need three branches: if, elif and else.

The program

python
n = float(input("Enter a number: "))

if n > 0:
    print("Positive")
elif n < 0:
    print("Negative")
else:
    print("Zero")

Typed in this example: -3.5. Press Run to type your own.

output
Enter a number: -3.5
Negative

How it works

Learn the idea: Control Flow: Conditionals