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

In this tutorial you will learn to write a simple Python Program to Check if a Number is Positive, Negative or 0

We can write this program by using if elif else and also by using nested if else statements.

Using if elif else statements

Python example program

 1 # Python Program to Check if a Number is Positive, Negative or 0.
 2 
 3 # Read Number from user
 4 number = float(input("Enter a number: "))
 5 
 6 # Check for Positive Number
 7 if number > 0:
 8    print("Number Entered is a Positive number")
 9 
10 #Check for Negative Number
11 elif number < 0:
12    print("Number Entered is a Negative number")
13 
14 # if Number is not Positive and not Negative then it is 0
15 else:
16    print("Number Entered is Zero")

Program Output : Run 1

Enter a number: 5

Number Entered is a Positive number

Program Output : Run 2

Enter a number: 0.001

Number Entered is a Positive number

Program Output : Run 3

Enter a number: -5

Number Entered is a Negative number

Program Output : Run 4

Enter a number: -0.00001

Number Entered is a Negative number

Program Output : Run 5

Enter a number: 0

Number Entered is Zero

Using nested if else statements

Python example program

 1 # Python Program to Check if a Number is Positive, Negative or 0
 2 
 3 # Read Number from user
 4 number = float(input("Enter a number: "))
 5 
 6 if number >= 0:
 7    if number == 0:
 8        print("Number Entered is Zero")
 9    else:
10        print("Number Entered is a Positive number")
11 else:
12    print("Number Entered is a Negative number")

Program Output : Run 1

Enter a number: 5

Number Entered is a Positive number

Program Output : Run 2

Enter a number: 0.0005

Number Entered is a Positive number

Program Output : Run 3

Enter a number: -6

Number Entered is a Negative number

Program Output : Run 4

Enter a number: -0.0004

Number Entered is a Negative number

Program Output : Run 5

Enter a number: 0

Number Entered is Zero