Python Tutorials

Python Programs

Python Check if Number is Positive, Negative, or Zero


Python Check if Number is Positive, Negative, or Zero

In this tutorial, we will learn how to check if a number is positive, negative, or zero in Python. We will cover the basic conditional statements to determine the sign of a number.


What is Number Sign Checking

Number sign checking is the process of determining whether a number is positive, negative, or zero. This is commonly done using conditional statements to compare the number to zero.


Syntax

The syntax to check if a number is positive, negative, or zero in Python is:

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


Checking if a number is positive, negative, or zero

We can use conditional statements to check the sign of a given number.

For example,

  1. Declare a variable number and assign it a value.
  2. Use an if statement to check if the number is greater than zero. If true, print "Positive".
  3. Use an elif statement to check if the number is less than zero. If true, print "Negative".
  4. Use an else statement to handle the case where the number is zero and print "Zero".
  5. Print the result based on the condition met.

Python Program

number = 5

# Check if the number is positive, negative, or zero
if number > 0:
    print("Positive")
elif number < 0:
    print("Negative")
else:
    print("Zero")

Output

Positive