Python Positive or Negative Number Checker

Check whether a number is positive, negative, or zero in Python using conditional branching.

Try Python Positive or Negative Number Checker Code

How it Works

Determining the sign of a number is one of the most fundamental operations in logical decision-making and mathematical computing.

We use Python's if-elif-else statements to check if the number is greater than zero (positive), less than zero (negative), or equal to zero.

This exercise reinforces fundamental boolean comparisons and conditional branching logic in Python.

Source Code

Checking a series of test inputs to classify them as positive, negative, or zero.

positive_negative.py
Try in Editor
def check_number(num):
    if num > 0:
        return "Positive"
    elif num < 0:
        return "Negative"
    else:
        return "Zero"

test_cases = [10, -5, 0]
for val in test_cases:
    print(f"Number {val:2d} is {check_number(val)}")
Terminal Output
Number 10 is Positive
Number -5 is Negative
Number  0 is Zero

Real-world Applications

  • Input validation in data pipelines
  • Sign-dependent calculation branching
  • Basic control flow learning

Frequently Asked Questions

Is zero considered positive or negative?

In standard mathematics and Python programming, zero is neither positive nor negative. It is classified as neutral or zero.

More Examples