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

In this example, we will write a simple program to take input number from the user and display if it is either positive, negative or zero. To better understand this example, make sure you have knowledge of the following tutorials:-

Source code using  if…elif…else statement to check if a number is positive or negative or zero:

number = int(input("Enter the value of a: "))
if number > 0:
    print("The number is positive")
elif number == 0:
    print("The number is zero")
else:
    print("The number is negative")

The output of the above program is:-

Enter the value of a: 0
The number is zero

Source code for Python nested statement to check if a number is positive or negative or zero:

number = int(input("Enter the value of a: "))
if number >= 0:
    if number == 0:
        print("The number is zero")
    else:
        print("The number is positive")
else:
    print("The number is negative")
print("The program continues")

The output of the above program is:-

Enter the value of a: 4
The number is positive
SHARE Python Program to Check if a Number is Positive, Negative or Zero

You may also like...

Leave a Reply

Your email address will not be published.

Share