Program to check if a number is positive, negative or zero in Python

Program to check if a number is positive, negative or zero in Python. This program with source code and output is provide simple example of if and else statement in Python. This is must to know program for beginners, class 11,12 and BTech computer science students. Download source code.

Program to check if a number is positive, negative or zero in Python

What are positive numbers ?

Positive Numbers: A number is said to be positive if the number has a value greater than 0, like 1, 2, 3, 5, 7, 9, 11, 13, etc. All the natural numbers are positive numbers.

What are Negative Numbers ?

Negative Numbers: If a given number has a value less than 0 like -1, -2, -3, -5, -7, -9, -11, -13, etc., then we can say that the given number is a negative number. Only rational and integer type numbers can have negative values or numbers.

Source code :

# Default function to run if else condition  
def NumberCheck(a):   
    # Checking if the number is positive  
    if a > 0:   
        print("Number given by you is Positive")   
    # Checking if the number is negative   
    elif a < 0:   
        print("Number given by you is Negative")   
    # Else the number is zero  
    else:   
        print("Number given by you is zero")  
# Taking number from user  
a = float(input("Enter a number as input value: "))  
# Printing result  
NumberCheck(a) 

Download Source code : For Download Click on the below Button

Step by step explaination :

Step 1:A function is defined as NumberCheck and take variable a as input.
def NumberCheck(a) :
Checking if the number is positive or negative or zero under NumberCheck(a) function.
if a >0:
print(“Number given by you is positive”)
elif a<0:
print(“Number given by you is negative”)
else:
print(“Number given by you is zero”)
Step 2: Enter a input value
a=float(input(“Enter a number as input value : “))
Step 3: The function is feed with the value
NumberCheck(a)

Output :

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test1.py 
Enter a number as input value: -6
Number given by you is Negative
>>> 
 RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test1.py 
Enter a number as input value: 6
Number given by you is Positive
>>> 
 RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test1.py 
Enter a number as input value: 0
Number given by you is zero
>>> 

Output Explanation :

Enter a number as input value is printed to capture the value.
Number is shown in category (positive, negative, zero).

Thank you for reading and learning from Program to check if a number is positive, negative or zero in Python. It is If and else program for beginners, class 11,12 and B Tech students. More programs for learning are given below in tutorial style and practical files are also provided.

Python Programs Archives – CS Study

Computer Science Practical file for class 12 Term-2 – CS Study

Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study

Leave a Comment

Your email address will not be published.