The provided Python program is designed to determine whether a given number is positive, negative, or zero. It begins by prompting the user to enter a numerical value using the input() function. The input is then converted to a floating-point number using the float() function to handle decimal values. The program proceeds to evaluate the number using an if-elif-else statement. If the number is greater than zero, it prints “The number is positive.” If the number is less than zero, it prints “The number is negative.” Finally, if the number is exactly zero, it prints “The number is zero.” This straightforward program allows users to quickly ascertain the sign of a given numerical input.
Source code
# Get input from the user
num = float(input("Enter a number: "))
# Check if the number is positive, negative, or zero
if num > 0:
print("The number is positive.")
elif num < 0:
print("The number is negative.")
else:
print("The number is zero.")
Description
- User Input:
- The program begins by using the
input()function to prompt the user to enter a number. - The entered value is then stored in the variable
num.
- The program begins by using the
num = float(input("Enter a number: "))
- Data Conversion:
- The entered value is converted to a floating-point number using the
float()function. This step is crucial for handling decimal values.
- The entered value is converted to a floating-point number using the
num = float(input("Enter a number: "))
- Conditional Checking:
- The program uses an
if-elif-elsestatement to check the value of the entered number. - If the number is greater than zero, it prints “The number is positive.”
- If the number is less than zero, it prints “The number is negative.”
- If the number is exactly zero, it prints “The number is zero.”
- The program uses an
if num > 0: print("The number is positive.") elif num < 0: print("The number is negative.") else: print("The number is zero.")
- Output:
- The program prints the result based on the conditions met. If the user enters
5, it will print “The number is positive.” If the user enters-3, it will print “The number is negative.” If the user enters0, it will print “The number is zero.”
- The program prints the result based on the conditions met. If the user enters
This program efficiently determines the sign of the entered number and provides a clear output based on the specified conditions.
Screenshot

