In this Python program, we will learn how to check if a given number is positive, negative, or 0. A Number is positive if the number is greater than 0 (number > 0). And if the number is less than 0 then it is a negative number.
Here is the source code of the program to check if a given number is positive, negative, or 0.
Program 1: With If...elif...else statement
# Python Program to Check if a Given Number is Positive, Negative or 0
# Take the User Input
num = float(input("Enter a number: "))
if num > 0:
print("Given Number is a Positive number (+)")
elif num == 0:
print("Given Number is equals to Zero (0)")
else:
print("Given Number is a Negative number (-)")
Enter a number: 5
Given Number is a Positive number (+)
Enter a number: -5
Given Number is a Negative number (-)
Program 2: With Nested if
# Python Program to Check if a Given Number is Positive, Negative or 0
# Take the User Input
num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Given Number is equals to Zero (0)")
else:
print("Given Number is a Positive number (+)")
else:
print("Given Number is a Negative number (-)")
Enter a number: 5
Given Number is a Positive number (+)
Enter a number: -6
Given Number is a Negative number (-)
Comments