Algorithm


1. Input a number
2. If number > 0:
      Print "Positive"
   Else if number < 0:
      Print "Negative"
   Else:
      Print "Zero"

Code Examples

#1 Example-Python Programing Using if...elif...else

Code - Python Programming

num = float(input("Enter a number: "))
if num > 0:
   print("Positive number")
elif num == 0:
   print("Zero")
else:
   print("Negative number")
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter a number: 2
Positive number

#2 Example- Pythom Programing Using Nested if

Code - Python Programming

num = float(input("Enter a number: "))
if num >= 0:
   if num == 0:
       print("Zero")
   else:
       print("Positive number")
else:
   print("Negative number")
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter a number: 0
Zero
Advertisements

Demonstration


Python Programing Example to Check if a Number is Positive, Negative or 0-DevsEnv