To check for positive, negative, or zero in python, you have to ask from user to enter a number to check whether that number is a positive number, negative number, or zero as shown in the program given here.
Following python program ask from user to enter any number to check for positive number, negative number or zero:
# Python Program - Check Positive Negative and Zero print("Enter 'x' for exit."); num = input("Enter any number: "); if num == 'x': exit(); try: number = int(num); except ValueError: print("Try to enter a number..exiting.."); else: if number < 0: print("It is a negative number."); elif number == 0: print("It is a zero."); elif number > 0: print("It is a positive number."); else: print(number, "is strange.");
Here is the sample run of the above Python program. This is the initial output asking from user to enter any number to check it out for whether the given or supplied number is a positive number, negative number, zero, or anything other than all these options:
Let's first check the above program for positive number by entering any positive number say 10 and press enter key to see the output given here in the below screenshot:
Now let's check for negative number by entering -10, a negative number:
Now again re-run the same program and check it out for zero as shown here:
Now let's type anything other than these options (that is, numbers) by typing any special character or any alphabet say $ and press enter key to see the output given here:
Here is the same program written and run directly on python shell.