About 3,690,000 results
Open links in new tab
  1. Python Program to Check if a Number is Positive, Negative or 0

    In this example, you will learn to check whether a number entered by the user is positive, negative or zero. This problem is solved using if...elif...else and nested if...else statement. Learn to code solving problems and writing code with our hands-on Python course.

  2. Python Check if a Number is Positive or Negative – PYnative

    Mar 31, 2025 · 4. Using NumPy’s sign Function. If you are working with NumPy, a popular library for numerical computing, you can use numpy.sign() that returns the sign of a number or an array of numbers.. numpy.sign(num) returns 1 for positive numbers, -1 for negative numbers, and 0 for zero. Based on this, you can print the corresponding message. Note: The Numpy library is not bundled with the default ...

  3. Python Program to check Number is Positive or Negative

    Write a Python Program to check whether the Number is Positive or Negative with a practical example. There are two traditional approaches to achieve the same, and they are using elif and nested statements. This program allows the user to enter any numeric value.

  4. Python - Check if a Number is Positive or Negative - Python

    To check if a given number is positive or negative, we can use relational operators like greater-than, less-than and compare it with zero. If the given number is greater than zero, then it is a positive number, or if less than zero, then it is a negative number, or …

  5. Python program that checks if a given number is positive, negative

    Jan 12, 2023 · The program prompts the user to enter a number using the input() function, and stores the value in the variable “number”. It then uses an if-elif-else statement to check the value of the number. If the number is greater than 0, it is positive.

  6. Python: Check if a number is positive, negative or zero

    Apr 16, 2025 · n = float(input('Input a number: ')) # Use a conditional expression (ternary operator) to determine if the number is positive, zero, or negative. # The conditional expression checks if the number is greater than 0, equal to 0, or less than 0.

  7. How to Test for Positive Numbers in Python

    The following Python snippet demonstrates how to test if an inputted number is positive, negative, or zero. The code is simple, straightforward, and works with any number or integer.

  8. Positive or Negative Number in Python - Sanfoundry

    Here is the source code of the Python Program to check whether a number is positive or negative. The program output is also shown below. print("Number is positive") else: print("Number is negative") 1. User must first enter the value and store it in a variable. 2. Use an if statement to make a decision. 3.

  9. Python Program to Check if a Number is Positive or Negative

    Determining whether a number is positive or negative is a basic yet essential task in programming, often serving as an introduction to conditional statements.

  10. How to Check Number is Positive, Negative, or Zero in Python

    Sep 6, 2023 · In order to check or verify if a number is positive, negative, or 0 in Python, using: 1. Using if-else Statements. Using an if-else statement is one of the traditional approaches for determining the sign of a number in Python. It enables you to define certain actions based on the specified conditions.