Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Program to find if the given number is positive or negative or 0 in C

Python code to check whether the given number is positive or negative or 0

Posted on October 8, 2020October 8, 2020

Table of Contents

  • Python code to check whether the given number is positive or negative or 0
    • Python code to check whether the given number is positive or negative or 0
      • Check whether the given number is positive or negative or 0- using standard method
      • Check whether the given number is positive or negative or 0- using User input
      • Check whether the given number is positive or negative or 0- using function
    • Related

Python code to check whether the given number is positive or negative or 0

In this tutorial, we will discuss the  Python code to check whether the given number is positive or negative or 0

In this post, we are going to learn how to check whether the given number is positive or Negative or zero  using 3 ways in Python language

 

The logic to check positive, negative or zero

  • Check the condition if(num<0), then number is negative
  • Check the condition if(num>0), then number is positive
  • Check the condition if(num==0), then number is zero

 

Python code to check whether the given number is positive or negative or 0

Check whether the given number is positive or negative or 0- using standard method

Program 1

#Pyton program to check number is positive or negative or zero
num=234
if(num>0):
    print("{0} is a positive number".format(num))
elif(num<0):
    print("{0} is a negative number".format(num))
else:
     print("you have entered zero")

When the above code is executed, it produces the following result

234 is a positive number

In this program,

  • integer variables num  is declared and initialized
  • The given numbers are tested whether it is positive, negative or zero using if- elif statements
  • Then,the program is displayed the output of using print() function

 

Check whether the given number is positive or negative or 0- using User input

Program 2

#Pyton program to check number is positive or negative or zero
num=int(input("Enter the number: "))
if(num>0):
    print("{0} is a positive number".format(num))
elif(num<0):
    print("{0} is a negative number".format(num))
else:
     print("you have entered zero")

When the above code is executed, it produces the following result

Case 1

Enter the number: 124
124 is a positive number

Case 2

Enter the number: -765
-765 is a negative number

Case 3

Enter the number: 0
you have entered zero

 

Approach

  • integer variable num is declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using input stream and store to the variable num
  • The given number is tested whether it is positive, negative or zero using if- else statements
  • Then,the program is displayed the output of using print() function,

 

 

Check whether the given number is positive or negative or 0- using function

Program 3

#Pyton program to check number is positive or negative or zero
num=int(input("Enter the number: "))
def FindPositive():
  if(num>0):
    print("{0} is a positive number".format(num))
  elif(num<0):
    print("{0} is a negative number".format(num))
  else:
     print("you have entered zero")
#FindPositive();

When the above code is executed, it produces the following result

Case 1

Enter the number: 36
36 is a positive number

case 2

Enter the number: -75
-75 is a negative number

case 3

Enter the number: 0
you have entered zero

 

Approach

 

  • integer variables num is declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using input stream and store the variable num.
  • Define the function  findPositive(); to find whether the number is Negative or Positive or zero
  • Call the function to produce output
  • finally, the program displays the output using print().

 

 

Suggested post

If statements in Python

operator in Python

Data type in Python

Function in Python

 

Similar post

Java program to find if the given number is positive or negative or 0

C program to find if the given number is positive or negative or 0

C++ program to find if the given number is positive or negative or 0

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes