How to check if a number is positive, negative or zero using Python?

PythonServer Side ProgrammingProgramming

Using if-elif-else

num = float(input("Enter a number: "))
if num > 0:
   print("Positive ")
elif num == 0:
   print("Zero")
else:
   print("Negative ")

using nested if

num = float(input("Enter a number: "))
if num >= 0:
   if num == 0:
       print("Zero")
   else:
       print("Positive")
else:
   print("Negative")
raja
Published on 28-Feb-2018 00:36:12
Advertisements