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 Read: How 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:
- Python 3 Program To Swap Two Numbers.
- Python 3 Program To Solve A Quadratic Equation.
- Python 3 Program to Calculate The Area of a Triangle.
- Python 3 Program to Find the Square Root of A Number.
- Python 3 Program To Add Two Numbers.
Output
Other Python Programs:
- Python 3 Program To Convert Celsius To Fahrenheit.
- Python 3 Program To Find Largest Element In An Array or List.
- Python 3 Program To Find The Sum of An Array.
- Python 3 Program to Convert Kilometers to Miles.
- Python 3 Program to Generate A Random Number.
Download Jupyter Notebook PDF.
B.Tech from DTU. Data Science and Machine Learning enthusiasts teamed up with CodeItBro to share my knowledge and expertise.