C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Python Program to check if a Number is Positive, Negative or ZeroHere, 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. 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.
Next TopicPython Number is Odd or Even
|