Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Check if Number is Positive, Negative, or Zero

Decide whether a value is positive, negative, or zero. A beginner Python exercise on float input, ordered comparisons, and choosing one if-elif-else branch.

BeginnerPhase 1 - Level 1: Simple ConditionsExample 1 of 10
check-if-number-is-positive-negative-or-zero.py
1# Take a number as input
2num = float(input("Enter a number: "))
3
4# Check if positive, negative, or zero
5if num > 0:
6 print("Positive")
7elif num < 0:
8 print("Negative")
9else:
10 print("Zero")

Output

Enter a number: 5
Positive

Enter a number: -3
Negative

Enter a number: 0
Zero

In this one

  • Convert text with float
  • Compare signs with zero
  • Follow exclusive branches

How it works

  1. 1

    Read num as a float.

  2. 2

    Test positive, then negative only if needed.

  3. 3

    Print the matched sign or the zero fallback.

Walk through Check if Number is Positive, Negative, or Zero

Input 5

  1. 1.float converts the response to 5.0.
  2. 2.5.0 > 0 is true, so Positive prints.
  3. 3.The elif and else branches are skipped.

Edge cases

What happens at zero?

What happens at zero?

Neither strict comparison succeeds, so Zero is printed.

Can I enter -0.5?

Can I enter -0.5?

Yes. float accepts it, and the negative branch runs.

What's going on

A sign check divides the number line into three parts. float converts the response from text to a number, so decimal values can be compared with zero.

Python tries num > 0 first, then num < 0 only if needed. The final else covers zero; it does not mean negative. With 5, the first branch prints Positive and the remaining tests are skipped.

What happens at zero? Neither strict comparison succeeds, so Zero is printed.

Can I enter -0.5? Yes. float accepts it, and the negative branch runs.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

How many classification messages appear per run?

Pick an answer to check it.

Question 2

What happens at zero?

Pick an answer to check it.

Questions people ask

What happens at zero?

Neither strict comparison succeeds, so Zero is printed.

Can I enter -0.5?

Yes. float accepts it, and the negative branch runs.

How many classification messages appear per run?

One.