# Python Program to check if a Number Is Positive Or Negative

## Check if a Number is Positive and Negative in Python

Given an integer input, The objective is to write a code to Check if a Number is Positive or Negative in C Language.

### Check if a Number is Positive and Negative in Python

Given an integer input, the objective is check whether the given integer is Positive or Negative. In order to do so we have the following methods,

1.  Method 1: Using Brute Force
2. Method 2: Using Nested if-else Statements
3. Method 3: Using ternary operator

We’ll discuss each method in-depth in the section below.

### Method 1: Using Brute Force

This method uses Brute Force to check whether a given integer is Positive or Negative.

### Python Code

Run
```num = 15
if num > 0:
print('Positive')
elif num < 0:
print('Negative')
else:
print('Zero')
```

### Output

```Positive
```

### Algorithm

This method uses Brute Force to check whether a given integer is Positive or Negative.

Algorithm for the above code is as follows,

• Initialize num as 15
• If the num > 0: it is a positive number.
• If the num < 0: it is a Negative number.
• Else the number has to be zero itself

### Method 2: Using Nested if-else Statements

This method uses a nested if-else Statements to check whether a given number is Positive or Negative.

### Python Code

Run
```num = 15
if num>=0:
if num==0:
print('Zero')
else:
print("Positive")
else:
print("Negative")
```

### Output

```Positive
```

### Algorithm

This method uses a nested if-else Statements to check whether a given number is Positive or Negative.

Algorithm for the above code is as follows,

• Initialize num as 15
• If the num >= 0
• If num == 0 : num is zero
• Else number has to be positive
• Else the number has to be negative

### Method 3: Using Ternary Operator

This method uses a ternary operator to check whether a number is Positive or Negative.

### Python Code

Run
```num =15
print("Positive" if num>=0 else "Negative")
```

### Output

```Positive
```

### Algorithm

This method uses a ternary operator in Python to check whether a number is Positive or Negative.

For a user input num

• Return “Positive” if num>=0 else “Negative”.

Algorithm for the above code is as follows,

• Initialize num as 15.
• print the output using ternary operator in python using print () function.

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

## Getting Started

### 23 comments on “Python Program to check if a Number Is Positive Or Negative”

• Mayur

I got plaed with 5 offers. All thanks to Prepnsta prime subscription. Want to thank you so much guys !

• imrahmankashif

Python Program:
n=int(input(“Enter a number: “))
if n==0:
print(“The number is Zero”)
elif n>0:
print(“The number is Positive”)
else:
print(“The number is Negative”

• kb03ff

if n==0:
print (“zero”)
elif n%2==0:
print (“pos”)
else:
print (“neg”)

• Kiran

num=int(input(“enter a number”))
if num==0:
print(“The number is zero”)
elif num>0:
print(“The number is positive”)
else:
print(“The number is negative”)

• Ranjeet

num = int(input(“Enter the number:”))
if num > 0:
print(f”This number is positive number: {num}.”)
elif num <0:
print(f"This is negative number: {num}.")
else:
print("Number is zero.")