codescracker


python

Python Program to Check Positive Negative Zero



« Previous Program Next Program »


Check Positive Negative Zero in Python

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.

Python Programming Code to Check Positive Negative Zero

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
		
while True:
	print("Enter 'x' for exit.")
	num = input("Enter any number: ")
	if num == 'x':
		break
	try:
		number = int(num)
	except ValueError:
		print("Please, enter a number...")
	else:
		if number < 0:
			print("It is a negative number.\n")
		elif number == 0:
			print("It is a zero.\n")
		elif number > 0:
			print("It is a positive number.\n")
		else:
			print(number, "is strange.\n")

Here is the sample run of the above Python program:

python check positive negative zero

« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test