Skip to content
Exercise · Q17

Q.Following is an algorithm to classify numbers as “Single Digit”, “Double Digit” or “Big”.
Classify_Numbers_Algo
INPUT Number
IF Number < 9
"Single Digit"
Else If Number < 99
"Double Digit"
Else
"Big"
Verify for (5, 9, 47, 99, 100 200) and correct the algorithm if required

Sikkim CbseNCERTSubjective· 3mImportance★★★★★est
97% · 35/36 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Testing the boundary values exposes the bug: with Number < 9 and Number < 99, the inputs 9 and 99 are misclassified — the conditions must be <= 9 and <= 99.

The idea (verification and boundary testing). An algorithm is verified by dry-running it on test data — and the most revealing test values are the boundaries between categories. Here the categories are single digit (1–9), double digit (10–99) and big (100+), so the values 9 and 99 sit exactly on the edges — and that is precisely where the given algorithm breaks. (The list "(5, 9, 47, 99, 100 200)" is read as the six values 5, 9, 47, 99, 100, 200 — the missing comma is a book misprint.)

Dry run of the algorithm as printed

NumberIF Number < 9Else IF Number < 99OutputExpectedVerdict
55 < 9 → true—Single DigitSingle Digit✓
99 < 9 → false9 < 99 → trueDouble DigitSingle Digit✗
47false47 < 99 → trueDouble DigitDouble Digit✓
99false99 < 99 → falseBigDouble Digit✗
100falsefalseBigBig✓
200falsefalseBigBig✓

Four of six pass; the two boundary values 9 and 99 fail because strict < excludes the boundary itself.

Corrected algorithm

Classify_Numbers_Algo (corrected)
INPUT Number
IF Number <= 9
     "Single Digit"
Else If Number <= 99
     "Double Digit"
Else
     "Big"

Python verification of the corrected version

for Number in [5, 9, 47, 99, 100, 200]: …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.