Python to Check if a Number is Positive, Negative or 0

Python to Check if a Number is Positive, Negative or 0

In this, we discuss whether a number is positive, negative or zero using Python Programming. 

Positive Numbers: A number is called a positive number if it has a value greater than zero. 

for example 1, 2, 3, 4 etc.


Negative numbers: If the value is less than zero then the number is called negative number.

for example -1, -2, -3, -4 etc.


In this example,You will learn how to check if the number entered is positive, negative or zero. This problem is solved using the if...elif...else and nested if.... else statement.

To understand the following program, you must have the knowledge to follow Python concepts:

Introduction to Python

Basics of Python


Steps:

1. Take the integer value and store it in the variable.

2. Use the if statement to find out if the number is positive or negative.

3. Exit.

The user must first enter the value and store it in the variable. Use the if statement to make a decision.

Let's take a look at how to check if a number is positive, negative or zero using Python code.

Python code:

n = int(input("enter any number n = "))
if (n>0):
print('number is positive')
elif (n<0):
print('number is negative')
else:
print('number is zero')
Output:
Case 1: enter any number n = -67
number is negative
Case 2: enter any number n = 67
number is positive