Python program to check if a given number is Positive or Negative or Zero
Now i am going to explain how to find a number is positive or negative or zero using python programming. Here i am going to apply if condition to check the number. if the number greater than 0 it is positive number. Less than 0 - negative number number =0- it is a zero.
Requirements
- Must install Python on your computer system.
- Notepad++
or
- Command prompt (CMD).
- You can use Python IDLE to type and run the program.
Simple steps just follow:
- Open Notepad or Python IDLE shell.
- Then type the below program in your notepad or Python IDLE shell.
- Then save a file with proper file name along with .py extension
- Then compile the file with python file_name.py (in Command prompt) or In Python Shell press F5 to run the program.
- All done
Program code (Python) Method-1
num = int(input("Enter a number: "))
if num > 0:
print(num,"is Positive number")
elif num == 0:
print(num,"- Zero")
else:
print(num,"is Negative number")
Program code (Python) Method-2
// nested if to find //
num = int(input("Enter a number: "))
if num >= 0:
if num == 0:
print(num,"- Zero")
else:
print(num,"is Positive number")
else:
print(num, "is Negative number")
Clear Definition
- Here 'num'- is a variable to store the value.
- input() is a function to get input.
- if , elif, else are the conditional checking the condition true or not.
- print() is a function to display the value.
Check the output
Output 1
Enter a number: 8
8 is Positive
-7 is Negative
0 - Zero
You may also check Find an integer is odd or even number using Python within 4 simple lines
For more Program Tips
8 is Positive
Output 2
Enter a number: -7-7 is Negative
Output 3
Enter a number: 00 - Zero
You may also check Find an integer is odd or even number using Python within 4 simple lines
For more Program Tips