Finding positive and negative number

We can use python language to create a simple program that identifies whether the  number is positive or negative.

Below is the logic

  1. Use if and else condition statement.
  2. If number is less than 0 than number is negative.
  3. If number is greater than 0 than number is positive.

In this blog we will ask user to enter any number. Using if..else condition statement to determine whether the number enter by user is positive or negative.

Getting input from user.

num = int(input('Please enter number: '))

Using if else condition to check whether number is greater than 0. If number is greater than 0, display number as positive otherwise display number as negative.

if num > 0:
    print('Number %s is Positive'%num)
else:
    print('Number %s is Negative'%num)

OUTPUT

Program to find Positive and Negative number
Please enter number: 6
Number 6 is Positive

Running the same program with different value

Program to find Positive and Negative number
Please enter number: -9
Number -9 is Negative

Complete Code

print('Program to find Positive and Negative number')
num = int(input('Please enter number: '))
if num > 0:
    print('Number %s is Positive'%num)
else:
    print('Number %s is Negative'%num)

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s