In this post, I am going to write a simple Python script to check if the entered number is a Positive number or a Negative number or Zero. This python program is helpful for students who are learning Python programming by themselves. Sometimes this kind of question asked in Interview as well.
Enough talking, let’s write the program now.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#get the value from user print ("Program to find positive or negative number") val = float(input("Enter a positive or negative number:")) #if the value is greater than zero then it is a positive number #or it is a negative number if val > 0: print ("You have entered a positive number") elif val < 0: print ("You have entered a negative number") else: print ("You have entered zero") |
Sample output of the above program:
Output 1:
1 2 3 |
Program to find positive or negative number Enter a positive or negative number:-57 You have entered a negative number |
Output 2:
1 2 3 |
Program to find positive or negative number Enter a positive or negative number:4 You have entered a positive number |
Output 3:
1 2 3 |
Program to find positive or negative number Enter a positive or negative number:0 You have entered zero |
It’s very simple if the entered value is greater than zero then it is a positive number or it is a negative number. If the value is equal to 0, you know it 🙂
I hope this program is helpful to you. Thanks for visiting my blog.