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

Here’s an example Python code to check if a number is positive, negative, or zero:

# Get input from user for the number to check
number = float(input("Enter a number: "))

# Check if the number is positive, negative, or zero
if number > 0:
    print("The number is positive")
elif number < 0:
    print("The number is negative")
else:
    print("The number is 0")

In this code, we first prompt the user to enter a number using the input() function and convert it to a floating-point number using the float() function. We then use a series of if, elif, and else statements to check if the number is positive, negative, or zero. If the number is greater than 0, we print a message indicating that the number is positive. If the number is less than 0, we print a message indicating that the number is negative. If the number is equal to 0, we print a message indicating that the number is 0.

When you run this code, it should prompt you to enter a number. After you enter a number, it should check if it is positive, negative, or zero and print the appropriate message, similar to the following:

Enter a number: -5
The number is negative

Note that you can modify the messages or the formatting of the output as needed.

Related Examples

1. Python Program to Print Hello world!

2. Calculate the multiplication and sum of two numbers

3. Python Program to Find the Square Root

4. Python Program to Calculate the Area of a Triangle

5. Python Program to Solve Quadratic Equation

6. Python Program to Swap Two Variables

7. Python Program to Generate a Random Number

8. Return the count of a given substring from a string

9. Print the following pattern

10. Python Program to check if the given number is a palindrome number

11. Python Program to print multiplication table form 1 to 10

12. Print downward Half-Pyramid Pattern with Star (asterisk)

13. Python Program to Convert Kilometers to Miles

14. Python Program to Find the Sum of Natural Numbers

15. Print the sum of the current number and the previous number in Python

Leave a Reply

Your email address will not be published. Required fields are marked *

Wordpress Social Share Plugin powered by Ultimatelysocial
Wordpress Social Share Plugin powered by Ultimatelysocial