In this tutorial, we will learn how to check if a number is positive, negative, or zero in Python. We will cover the basic conditional statements to determine the sign of a number.
Number sign checking is the process of determining whether a number is positive, negative, or zero. This is commonly done using conditional statements to compare the number to zero.
The syntax to check if a number is positive, negative, or zero in Python is:
if number > 0:
print("Positive")
elif number < 0:
print("Negative")
else:
print("Zero")
We can use conditional statements to check the sign of a given number.
For example,
number
and assign it a value.if
statement to check if the number is greater than zero. If true, print "Positive".elif
statement to check if the number is less than zero. If true, print "Negative".else
statement to handle the case where the number is zero and print "Zero".number = 5
# Check if the number is positive, negative, or zero
if number > 0:
print("Positive")
elif number < 0:
print("Negative")
else:
print("Zero")
Positive