In this simple Python program, we have to check the entered number or value is positive, negative, or zero. For that, we have to know the number is greater than zero or less than zero;
In this basic python program, we need to check the number is greater than or less than zero also, we if the number is zero itself. So in the Python program, After we accept the input from the user using the input function and convert that string to an integer using an int function, save that input in a variable. Then use the
if-else condition in python and
elif the decision-making statement for checking the number is greater than or less than zero. Let's break the code step by step.
STEP 1: Accept the number from the user using the input statement. (In python, accept values in string format only so we have to use an int to convert that string to an integer.)
STEP 2: We use
if condition statement to check the number is less than zero, and if that condition is satisfied, then we have to print that the given value is negative.
STEP 3: Use statement
elif [which is similar to else if statement in C language] to check the number is greater than zero. And if that condition is true, then print its positive.
STEP 4: Use else statement to print the given number is zero. In this python program, we make familiar with "
if condition " and
elif statement" and "else statement.."
number = int(input("Enter the number: ")) if number < 0: print("The entered value is negative.") elif number > 0: print("The entered value is positive.") elif number == 0: print("The entered value is zero.") else: print("Invalid input")
Enter the number : 2 The entered value is positive.