Python Program to Check if a Number is Positive, Negative or 0

Check if a Number is Positive, Negative or 0

CODE OUTPUT

Using if…elif…else

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

if num > 0:

print(“Positive number”)

elif num == 0:

print(“Zero”)

else:

print(“Negative number”)

Enter a number: 2Positive number

 

Using Nested if

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

if num >= 0:

if num == 0:

print(“Zero”)

else:

print(“Positive number”)

else:

print(“Negative number”)

Enter a number: 0Zero
The output of both programsĀ are going to beĀ same

Questions