by BehindJava

Write a program to check if a Number is Positive, Negative or 0 in Python

Home » python » Write a program to check if a Number is Positive, Negative or 0 in Python

In this tutorial we are going to check if a Number is Positive, Negative or 0 in Python.

num = float(input("Enter a number: "))  
if num > 0:  
 print("{0} is a positive number".format(num))  
elif num == 0:  
   print("{0} is zero".format(num))   
else:  
   print("{0} is negative number".format(num))   

A number is positive if it is greater than zero. We check this in the expression of if. If it is False, the number will either be zero or negative. This is also tested in subsequent expression.