How to Determine If a Number Is (+) or (-) or 0 in Python


In this example, we can learn about how to judge whether the given number is positive or negative, or “0” in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input("Please input a number: "))
if n == 0:
    print("\"0\" is neither positive nor negative.")
else:
    if n > 0:
        print("The number is positive.")
    else:
        print("The number is negative.")

Output:

Please input a number: 10
The number is positive.

Please input a number: -8
The number is negative.

Please input a number: 0
"0" is neither positive nor negative.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement