Python – Positive or Negative

 

CHECK FOR POSITIVE OR NEGATIVE IN PYTHON
 
Using Nested if

 

Program

 

 #Python program to check the sign of a number

num = float(input(“Enter a number: “))

if num >= 0:

if num == 0:

print(“Zero”)

else:

print(“Positive number”)

else:

print(“Negative number”)

 

input(“Press Enter to Exit”)

 

Output

 

 

 Using if…elif…else

 

Program

 

#Python program to check the sign of a number

 

num = float(input(“Enter a number: “))

if num > 0:

print(“Positive number”)

elif num == 0:

print(“Zero”)

else:

print(“Negative number”)

 

input(“Press Enter to Exit”)

 

Output