Python Program to check if a Number Is Positive Or Negative

Check if a Number is Positive and Negative in Python

Given an integer input, The objective is to write a code to Check if a Number is Positive or Negative in C Language.

Check if a Number is Positive or Negative in Python

Check if a Number is Positive and Negative in Python

Given an integer input, the objective is check whether the given integer is Positive or Negative. In order to do so we have the following method,

  1.  Method 1: Using Brute Force
  2. Method 2: Using Nested if-else Statements
  3. Method 3: Using ternary operator

We’ll discuss each method in-depth in the section below.

Method 1: Using Brute Force

This method uses Brute Force to check whether a given integer is Positive or Negative.

Python Code

Run
num = 15
if num > 0:
    print('Positive')
elif num < 0:
    print('Negative')
else:
    print('Zero')

Output

Positive

Algorithm

This method uses Brute Force to check whether a given integer is Positive or Negative.

Algorithm for the above code is as follows,

  • Initialize num as 15
  • If the num > 0: it is a positive number.
  • If the num < 0: it is a Negative number.
  • Else the number has to be zero itself

Method 2: Using Nested if-else Statements

This method uses a nested if-else Statements to check whether a given number is Positive or Negative.

Python Code

Run
num = 15
if num>=0:
    if num==0:
        print('Zero')
    else:
        print("Positive")
else:
    print("Negative")

Output

Positive

Algorithm

This method uses a nested if-else Statements to check whether a given number is Positive or Negative.

Algorithm for the above code is as follows,

  • Initialize num as 15
  • If the num >= 0
    • If num == 0 : num is zero
    • Else number has to be positive 
  • Else the number has to be negative

Method 3: Using Ternary Operator

This method uses a ternary operator to check whether a number is Positive or Negative.

Python Code

Run
num =15
print("Positive" if num>=0 else "Negative")

Output

Positive

Algorithm

This method uses a ternary operator in Python to check whether a number is Positive or Negative.

For a user input num

  • Return “Positive” if num>=0 else “Negative”.

Algorithm for the above code is as follows,

  • Initialize num as 15.
  • print the output using ternary operator in python using print () function.

Getting Started

27 comments on “Python Program to check if a Number Is Positive Or Negative”


  • Ramesh

    num=int(input(“enter a number”))
    If num>0:
    print(“it is a positive number”)
    else:
    print(“it is a negative number”)


  • Abhishek

    *********************for checking no is positive or negetive******************************

    var = int(input(“ENTER THE NUMBER:— “))
    if (var > 0):
    print(“ENTER NO IS +VE “)

    elif (var == 0):
    print(“ENTER NO IS NEITHER +VE OR -VE”)

    else:
    print(“ENTERD NO IS -VE “)

    *******************for checking no is positive or negetive******************************


  • Abhishek

    # Python Program to check if a Number Is Positive Or Negative
    var = int(input(“ENTER THE NUMBER:— “))
    if (var > 0):
    print(“ENTER NO IS +VE “)

    elif (var == 0):
    print(“ENTER NO IS NEITHER +VE OR -VE”)

    else:
    print(“ENTERD NO IS -VE “)


    • Abhishek

      var = int(input(“ENTER THE NUMBER:— “))
      if (var > 0):
      print(“ENTER NO IS +VE “)

      elif (var == 0):
      print(“ENTER NO IS NEITHER +VE OR -VE”)

      else:
      print(“ENTERD NO IS -VE “)


  • Pradeep

    num=int(input(“Insert a number”))
    if num>0:
    print(“The Number is postive”)
    elif num==0:
    print(“The number is zero”)
    else:
    print(“The number is Negative”)


  • Raaz

    a = int(input(“Enter The Number To Find”))
    if a>0:
    print(“The Number Is Positive”)
    elif a<0:
    print("The Number Is Negative")
    elif a==0:
    print("The Number Is Zero")


  • karan

    N=int(input(“enter any number”))
    if(N›=0):
    print(“Positive number”)
    else:
    print(“Negative number”)


  • Amarnadh

    number = int(input(“Enter your favorite number:”))
    if number > 0:
    print(“The number is positive”)
    elif number < 0:
    print("The number is Negitive")
    else:
    print("You entered ZERO")


  • rohitnamdev876

    n = int(input(“Enter the number for check : “))
    if n >= 0:
    print(“Number is positive “)
    else:
    print(“Number is nagative”)


  • 18-513

    num = int(input(“Enter the Number: “))

    if num > 0:
    print(f” Given {num} is Positive Number”)
    elif num < 0:
    print(f"Given {num} is Negative Number")

    else:
    print(f"Given {num} is NUll Number")


  • Pooja

    n=int(input(“Enter a number: “))
    if n==0:
    print(“You entered zero”)
    elif n>0:
    print(“The number is positive”)
    else:
    print(“The number is negative”)


  • lohith

    num = int(input(“Insert a number:”))
    if num > 0:
    print(“The number is Positive”)
    elif(num==0):
    print(“The number is zero”)
    else:
    print(“The number is Negative”)


    • Vikas Kumar

      num=int(input(“enter the no”))
      if (num>0):
      print(“no is positive”)
      elif(num<0):
      print("No is negative")
      else:
      print("nor postive nor negative")


    • Mda

      def negPos(n1):
      if n1==0:
      print(“You Entered Zero”)
      elif n1<0:
      print("negative")
      else:
      print("positive")

      negPos(int(input("Insert the number")))


    • M

      num=int(input(“entter the number:”))
      if num<0:
      print(str(num) +"number id negartive")
      elif num == 0:
      print(str(num) +"number is equal")
      else:
      print(str(num) +"number is positive")


    • Amarnadh

      number = int(input(“Enter your favorite number:”))
      if number > 0:
      print(“The number is positive”)
      elif number < 0:
      print("The number is Negitive")
      else:
      print("You entered ZERO")