• Uncategorized

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...


Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Attempt to read property "cat_name" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 14

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/functions.php on line 37

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 15

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 15
Share