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.