About 1,170,000 results
Open links in new tab
  1. 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 ...

  2. Python Program to Check if a Number is Positive, Negative or 0

    Write a function to return 'Up' if the input number is positive, 'Down' if it's negative, and 'Zero' if it's zero.

  3. Python - How do I return True for a positive number?

    Jan 23, 2023 · So I have to fill in the blanks in the below code to show True for a positive value and None for any other value. def is_positive (number): if ---: return --- On running the code I wrote I am getting the following error: Not quite, is_positive (-5) returned None instead of None. Remember that positive numbers are those bigger than zero (x > 0).

  4. How to Test for Positive Numbers in Python

    The code uses an if...elif...else statement to determine if a number is greater than 0 (in which case it has to be positive), elif a number equals zero (in which case it's neither positive nor negative...it's simply zero), or else it's less than zero (negative).

  5. How to Check If a Number Is Positive in Python | LabEx

    Learn how to check if a number is positive in Python! This tutorial covers defining positive numbers, comparing with zero using `if` statements, and handling both integers and floats in your Python code.

  6. 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 …

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

    Sep 6, 2023 · 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. More specifically, this statement can assist in verifying if a number is positive, negative, or zero.

  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 3 program to check if a number is positive

    Python 3 program to test if a number is positive or negative : In this tutorial, we will learn how to test if a number is positive or negative. We will also check if the number is zero.

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

    Oct 7, 2019 · The Python program defines a function check_number_sign that takes a number as input and uses conditional statements (if, elif, else) to determine whether the number is positive, negative, or zero. The input function is employed to gather user input, and the result is displayed.

Refresh