Python Program to Check Whether a Number is Positive or Negative

This is a Python Program to check whether a number is positive or negative.

Problem Description

The program takes a number and checks whether it is positive or negative.

Problem Solution

1. Take the value of the integer and store in a variable.
2. Use an if statement to determine whether the number is positive or negative.
3. Exit.

Program/Source Code

Here is the source code of the Python Program to check whether a number is positive or negative. The program output is also shown below.

 
n=int(input("Enter number: "))
if(n>0):
    print("Number is positive")
else:
    print("Number is negative")
Program Explanation

1. User must first enter the value and store it in a variable.
2. Use an if statement to make a decision.
3. If the value of the number is greater than 0, “Number is positive” is printed.
4. If the value of the number if lesser than 0, ”Number is negative” is negative.

advertisement
advertisement
Runtime Test Cases
 
Case 1:
Enter number: 45
Number is positive
 
Case 2:
Enter number: -30
Number is negative

Sanfoundry Global Education & Learning Series – Python Programs.

To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.