TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Python Check Number Positive Negative or Zero

Python Check Number Positive Negative or Zero for beginners and professionals with programs on basics, controls, loops, functions, native data types etc.

<< Back to PYTHON

Python Program to check if a Number is Positive, Negative or Zero

Here, we will learn to write a Python program through which we can check if the given number is positive, zero, or negative.

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.

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.

Python Condition And Loops1

Let us look at the following example to understand the implementation

Example:

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

Output:

Enter a number as input value: -6
Number given by you is Negative

Explanation:

We have used a nested if else condition in the program to check the number. When the user gives an input number, the program will first check if the value of the number is greater than 0 (if yes, it will print positive and the program ends), otherwise it will check if the value is less than 0 and it last it will print that number is 0.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf