Python program to check if a given number is Positive or Negative or Zero-Simple steps

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.

Positive-Negative 

Requirements

  • Must install Python on your computer system.
  • Notepad++
  • Command prompt (CMD).
                     or 
  • You can use Python IDLE to type and run the program. 

Simple steps just follow:

  1. Open Notepad or Python IDLE shell.
  2. Then type the below program in your notepad or Python IDLE shell.
  3. Then save a file with proper file name along with .py extension 
  4. Then compile the file with python file_name.py (in Command prompt) or In Python Shell press F5 to run the program.
  5. 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


Output 2

Enter a number: -7

-7 is Negative 


Output 3

Enter a number: 0

0 - Zero


You may also check Find an integer is odd or even number using Python within 4 simple lines

For more Program  Tips

If you any doubts, Please let me know

Previous Post Next Post

Contact Form