Check Positive, Negative, or Zero

Determine whether a given number is positive, negative, or zero.

BeginnerTopic: Basic Python Programs
Back

What You'll Learn

  • Using relational operators > and <
  • Designing mutually exclusive condition chains
  • Handling the special case of zero

Python Check Positive, Negative, or Zero Program

This program helps you to learn the fundamental structure and syntax of Python programming.

Try This Code
# Program to check if a number is positive, negative, or zero

num = float(input("Enter a number: "))

if num > 0:
    print(num, "is positive")
elif num < 0:
    print(num, "is negative")
else:
    print("The number is zero")
Output
Enter a number: -3
-3.0 is negative

Step-by-Step Breakdown

  1. 1Read a number from the user.
  2. 2Check if it is greater than 0 and print positive.
  3. 3Else if it is less than 0, print negative.
  4. 4Otherwise, print that it is zero.

Understanding Check Positive, Negative, or Zero

We divide all real numbers into three disjoint cases:

1.Greater than 0 → positive.
2.Less than 0 → negative.
3.Exactly 0 → zero.

An if-elif-else chain is perfect for mutually exclusive conditions like these.

Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.