Python Program to check the number is positive, negative or zero

In this simple Python program, we have to check the entered number or value is positive, negative, or zero. For that, we have to know the number is greater than zero or less than zero;

  • If the number is greater than zero, then the given number is Positive.
  • If the number is less than zero, the given number is Negative.
  • If the number is equal to zero, the user input given is Zero.

Here, we make familiar with "if condition ", elif statement" and "else statement". For a better understanding of these conditional statements in python we always recommend you to learn the basic topics of Python programming listed below:

How to implement a number check in python programming?

In this basic python program, we need to check the number is greater than or less than zero or the number is zero itself. So in the Python program, we accept the input from the user using the input function and convert that string to an integer using a int() function also, save that input into a variable. Then use the if-elif-else conditional statements in python for checking the number is greater than or less than zero. Let's break the code step by step.

ALGORITHM

STEP 1: Accept the number from the user using the input() function. In python, accept values in string format only so we have to use an int() to convert that string to an integer.

STEP 2: We use if conditional statement to check if the number is less than zero, and if that condition is satisfied, then we have to print that the given value is negative.

STEP 3: Use statement elif [which is similar to else if statement in C language] to check if the number is greater than zero. And if that condition is true, then print its positive.

STEP 4: Use else statement to print the given number is zero.

 

Python Source Code

                                          number = int(input("Enter the number: "))

if number < 0:

    print("The entered value is negative.")

elif number > 0:

    print("The entered value is positive.")

elif number == 0:

    print("The entered value is zero.")
else:

    print("Invalid input")
                                      

OUTPUT

Enter the number : 2

The entered value is positive.