Python Programming: Positive, Negative or Zero

Example

Input
enter the number 5
Output 
The number is positive

Required to Know

Use of Variables, Use of different operators like assignment or arithmetic operators, Use of functions like print(), and input(), Use of If-else, and Use of Data types.

Steps

  • Take the number as an input from the user.

  • Check if the number is positive or negative or Zero.

    • If the number is greater than zero, print positive.

    • If the number is less than zero, print negative.

    • Otherwise, print zero.

Condition.

if(num>0):
    print("The number is positive")
elif(num<0):
    print("The number is negative")
else:
    print("The number is zero")

Program

# This program determines whether a number is positive, negative, or zero.
num = int(input("Enter the number: "))
# Check if the number is positive.
if num > 0:
    # Print "The number is positive."
    print("The number is positive.")
# Check if the number is negative.
elif num < 0:
    # Print "The number is negative."
    print("The number is negative.")
# Otherwise, the number is zero.
else:
    # Print "The number is zero."
    print("The number is zero.")