0
4.0kviews
Write a Python Program to Check if a Number is Positive, Negative or 0
1 Answer
0
361views

Using if...elif...else

Code:-

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

Using Nested if

Code:-

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

Output:-

enter image description here

enter image description here

enter image description here

Create a free account to keep reading this post.

and 2 others joined a min ago.

Please log in to add an answer.