Kalebu Jordan

Become a Pro Python Developer

On this tutorial we will learn how to build a Simple Python Program to Check whether a given number is positive or negative.

This tutorial introduces us to conditional statement if else

Program overview

In order to determine whether a given number is positive or negative we need to know if that number is greater or less than 0.

Instructions summary

  • Getting a number from user
  • Checking If number is greater than 0
  • If number is greater than 0 is positive else the number is negative

number.py

#Getting number from user
number = int(input('Enter any number: '))

#Checking number state
if number>0:
    print('The number is positive')
else:
    print('The number is negative')

Running our Program

kalebu@kalebu-PC:~$ python3 number.py 
Enter any number: 12
The number is positive

------------------------------

kalebu@kalebu-PC:~$ python3 number.py 
Enter any number: -34
The number is negative

Hope you find this post interesting , don’t forget to subscribe to get more tutorials like this

In case of any suggestion or comment , drop it on the comment box and I will reply to you immediately.

Leave a Reply

error

Enjoy this blog? Please spread the word :)