Skip to content
Home » Blog » Python Program to Check if a Number is Positive, Negative or 0

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

Program to Check if a Number is Positive, Negative or 0

In this example, you will learn to check whether the user entered Number is Positive, Negative or 0

This Program to find Number is Positive, Negative or 0 can be solved using if…elif…else and nested if…else statement.

To understand this example, you should have knowledge of following Python programming topics:

  1. Python if…else Statement
  2. Python Input, Output and Import

Program to Check if a Number is Positive, Negative or 0 using if…elif…else

num = float(input("Enter a number: "))
if num > 0:
   print("Positive number")
elif num == 0:
   print("Zero")
else:
   print("Negative number")

Output

Enter a number: 2
Positive number
Python Program to Check if a Number is Positive, Negative or 0 using if…elif…else

Here, we have used the if...elif...else statement. We can do the same thing using nested if statements as follows.

Program to Check if a Number is Positive, Negative or 0 using Using Nested if

num = float(input("Enter a number: "))
if num >= 0:
   if num == 0:
       print("Zero")
   else:
       print("Positive number")
else:
   print("Negative number")

Output

Enter a number: 2
Positive number
Python Program to Check if a Number is Positive, Negative or 0 using Using Nested if

If you notice the output of both the Programs is the same, so we can use any method to Check if a Number is Positive, Negative or zero.

Ask your questions and clarify your doubts on the Program to Check if a Number is Positive, Negative or zero by commenting. Python Documentation

Related Program

  1. Python Program to Find LCM
  2. Python Program to Find HCF or GCD
  3. Python Program To Display Powers of 2 Using Anonymous Function
  4. Python Program to Display Calendar
  5. Python Program to find the Square Roots
  6. Python Program to Shuffle Deck of Cards
  7. Python program convert decimal number to binary number using recursion
  8. Python Program to Find Factorial of a Number Using Recursion
  9. Python Program to Check if a Number is Positive, Negative or 0
  10. Python Program to Display Fibonacci Sequence Using Recursion