Skip to main content

Write a python program to identify the given number is POSITIVE,NEGATIVE OR ZERO by using IF ELSE IF Statement

Description

This Python code assesses the sign of a numerical value, 'num,' to determine if it's positive, negative, or zero. It uses conditional statements (if, elif, and else) to classify the number and prints an appropriate message.

Code

program3c.py
num=-10
if num>0:
print("Number is positive")
elif num<0:
print("Number is negative")
else:
print("Number is zero")

Explanation of above code

  • The Python code's purpose is to assess the sign of a numerical value, 'num,' determining whether it's positive, negative, or zero.
  • It starts by initializing the variable 'num' with an initial value of -10.
  • The code utilizes a series of conditional statements to evaluate the sign of the number.
  • It begins with an 'if' statement to check if 'num' is greater than 0. If this condition is met, it prints 'Number is positive.'
  • If 'num' is not greater than 0, the code proceeds to an 'elif' statement (short for 'else if') to check if 'num' is less than 0. If this condition is satisfied, it prints 'Number is negative.'
  • If neither the 'if' nor 'elif' conditions are met, the code moves to the 'else' block and prints 'Number is zero.'
  • In the specific context of this code, where 'num' is initially set to -10, it falls into the second condition (elif), indicating that the number is negative. Therefore, the code will output 'Number is negative.' This code provides a basic example of using conditional statements to categorize numerical values based on their sign.

Learn more

Reference