How to detect Positive ,Negative or Zero Numbers in Python ?

How to detect Positive, Negative or Zero Numbers in Python ?

In this blog post, you will learn to check whether a number entered by the user is positive, negative or zero. 

# How to detect Positive, Negative or Zero Numbers in Python ?
num = int(input("Enter any number: "))
if num > 0:
   print("This is a Positive number")
elif num == 0:
   print("Zero")
else:
   print("This is a Negative number")

Output:

Enter a number: 4
This is a Positive number

No comments

Powered by Blogger.