Home » Blog » Python Program to Check if a Number is Positive, Negative or 0

# Python Program to Check if a Number is Positive, Negative or 0 #### In this example, you will learn to check whether the user entered Number is Positive, Negative or 0

This Program to find Number is Positive, Negative or 0 can be solved using if…elif…else and nested if…else statement.

To understand this example, you should have knowledge of following Python programming topics:

1. Python if…else Statement
2. Python Input, Output and Import

#### Program to Check if a Number is Positive, Negative or 0 using if…elif…else

``````num = float(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")``````

Output

``````Enter a number: 2
Positive number``````

Here, we have used the `if...elif...else` statement. We can do the same thing using nested `if` statements as follows.

#### Program to Check if a Number is Positive, Negative or 0 using Using Nested if

``````num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")``````

Output

``````Enter a number: 2
Positive number`````` Python Program to Check if a Number is Positive, Negative or 0 using Using Nested if

If you notice the output of both the Programs is the same, so we can use any method to Check if a Number is Positive, Negative or zero.

Ask your questions and clarify your doubts on the Program to Check if a Number is Positive, Negative or zero by commenting. Python Documentation

Related Program