Python Check if a Number is Positive, Negative or Zero

avatar
Published: Jun 09, 2022 - Updated: Jun 23, 2022

In this snippet, we will learn how to check positive number, negative number and zero in Python.

Using if...elif...else

Let's have a look at the example using if…elif…else:

num = float(input("Enter a number: "))
if num > 0:
   print("Positive number.")
elif num == 0:
   print("The number is zero!")
else:
   print("Negative number.")

Using Nested if

Using nested if:

num = float(input("Enter a number: "))
if num >= 0:
    if num == 0:
        print("The number is zero!")
    else:
        print("Positive number.")
else:
    print("Negative number.")