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

Positive Numbers Sum Check

Check that two numbers are positive and their sum is below one hundred. A Python exercise on three linked tests, strict boundaries, and failed conditions.

IntermediatePhase 1 - Level 4: Logical Operators & Compound StatementsExample 6 of 10
positive-numbers-sum-check.py
1# Take two numbers
2num1 = float(input("Enter first number: "))
3num2 = float(input("Enter second number: "))
4
5# Check conditions
6if num1 > 0 and num2 > 0 and (num1 + num2) < 100:
7 print("Both positive and sum < 100")
8else:
9 print("Condition not met")

Output

Enter first number: 30
Enter second number: 40
Both positive and sum < 100

Enter first number: 50
Enter second number: 60
Condition not met

In this one

  • Require three conditions
  • Test a strict sum limit
  • Reject zero as positive

How it works

  1. 1

    Read both values as floats.

  2. 2

    Check each is positive and their sum below one hundred.

  3. 3

    Print the combined-condition result.

Edge cases

Does 40 and 60 pass?

Does 40 and 60 pass?

No. A sum of exactly one hundred is excluded.

Does 0 and 20 pass?

Does 0 and 20 pass?

No. Zero is not strictly positive.

What's going on

The pair must meet three requirements at once. Both individual values must exceed zero, and their combined value must be less than one hundred.

and rejects the pair as soon as a requirement fails. With 30 and 40, all tests pass. With 50 and 60, the values are positive but their sum is too large. Checking only the sum would wrongly allow some negative inputs.

Does 40 and 60 pass? No. A sum of exactly one hundred is excluded.

Does 0 and 20 pass? No. Zero is not strictly positive.

Quiz

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

Question 1

Which pair meets all conditions?

Pick an answer to check it.

Question 2

Does 40 and 60 pass?

Pick an answer to check it.

Questions people ask

Does 40 and 60 pass?

No. A sum of exactly one hundred is excluded.

Does 0 and 20 pass?

No. Zero is not strictly positive.

Which pair meets all conditions?

30 and 40.