Python 3 Program To Check If Number Is Positive Or Negative

0
375

python 3 program to check number is positive

In this tutorial, you will find a simple Python 3 program to check if a number is positive or negative. Before moving ahead, you should know about the basics of Python programming language. If you have just started your Python journey, then do check out these best books for beginners to learn Python.

Also ReadHow To Use ArcGIS API for Python and Jupyter Notebooks.

Python 3 program to check if a number is positive, negative or 0

We can easily do it using Python elif loop where we can check three conditions to see if the number entered by the user is positive or negative.

Condition 1: If the user input is greater than 0, then the number is positive.

Condition 2: If the user input is less than 0, then the number is negative.

Condition 3: If the other two conditions are false, then the number is zero.

Source Code:

num = float(input("enter any number: "))

if num > 0:
    print("+ve number")

elif num < 0:
    print("-ve number")

else:
    print("Zero")

Run The Program

Other Python 3 programs:

  1. Python 3 Program To Swap Two Numbers.
  2. Python 3 Program To Solve A Quadratic Equation.
  3. Python 3 Program to Calculate The Area of a Triangle.
  4. Python 3 Program to Find the Square Root of A Number.
  5. Python 3 Program To Add Two Numbers.

Output

output of python program to check if a number is positive or negative

Other Python Programs:

  1. Python 3 Program To Convert Celsius To Fahrenheit.
  2. Python 3 Program To Find Largest Element In An Array or List.
  3. Python 3 Program To Find The Sum of An Array.
  4. Python 3 Program to Convert Kilometers to Miles.
  5. Python 3 Program to Generate A Random Number.

Download Python Source File.

Download Jupyter Notebook PDF.