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
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.
- 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
#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.