Check value

Python program to check whether a number is Positive or Negative or Zero

Python program to check whether a number is Positive or Negative or Zero

problem – Python program to check whether a number is Positive or Negative or Zero

In this tutorial, we will discuss a concept in Python  program to check whether a number is Positive or Negative or Zero

In this post, we will learn how to check if the number is positive or negative or zero in Python programming language

 

The logic of the program

If a number is greater than zero it is a positive number – (if the number>=0)

If a number is less than to zero it is a Negative number – (if the number<=0)

Otherwise, if the number is equal to zero the number is zero – (if the number==0)

 

Python program to number is Positive or Negative or Zero

Using if elif statements

Program 1

This program allows the user to enter a number and check if the number(entered by the user) is positive or negative or zero using if elif statements

number=int(input("Enter the value of number: "))
if number>0:
    print("The number is positive")
elif number==0:
    print("The number is zero")
else:
    print("The number is Negative")

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

case 1

Enter the value of number: 25
The number is positive

 

case 2

Enter the value of number: -10
The number is Negative

 

case 3

Enter the value of number: 0
The number is zero

 

 

Using Nested if  statements

Program 2

This program allows the user to enter a number and check if the number(entered by the user) is positive or negative or zero using Nested if  statements

number=int(input("Enter the value for number: "))
if number>=0:
    if number==0:
         print("The number is zero")
    else:
         print("The number is positive")
else:
    print("The number is Negative")

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

Case 1

Enter the value for number: 12
The number is positive

case 2

Enter the value for number: -15
The number is Negative

case 3

Enter the value for number: 0
The number is zero

 

Similar post

Java program to check whether a number is Positive or Negative or Zero

C program to check whether a number is Positive or Negative or Zero

C++ program to check whether a number is Positive or Negative or Zero

C code to check whether a number is prime or not

C++ program to check whether a number is prime or not

Python  program to check whether a number is prime or not

Java program to check whether a number is prime or not

 

 

Suggested for you

Python data type

Python if condition

Python operator

 

 

C++ program to check whether a number is Positive or Negative or Zero
Java program to find odd or even number using switch statements
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

1 day ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

4 days ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 week ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

2 months ago