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

Check Digit Count Type

Classify an integer as single-digit, double-digit, or multi-digit. Students follow Python abs, ordered size thresholds, and how zero and negative inputs behave.

IntermediatePhase 1 - Level 3: Math and Number LogicExample 4 of 10
check-digit-count-type.py
1# Take number
2num = abs(int(input("Enter a number: ")))
3
4# Check digit count
5if num < 10:
6 print("Single-digit")
7elif num < 100:
8 print("Double-digit")
9else:
10 print("Multi-digit")

Output

Enter a number: 5
Single-digit

Enter a number: 45
Double-digit

Enter a number: 123
Multi-digit

In this one

  • Ignore an integer sign
  • Classify magnitude thresholds
  • Cover three-or-more digits

How it works

  1. 1

    Apply abs to the converted integer.

  2. 2

    Test magnitude below ten, then below one hundred.

  3. 3

    Print the appropriate digit-size category.

Edge cases

How is zero classified?

How is zero classified?

Single-digit, because its magnitude is below ten.

What happens for -100?

What happens for -100?

abs makes it 100, which reaches Multi-digit.

What's going on

abs removes a negative sign before counting by size. The code does not loop through digits; it compares the resulting magnitude with ten and one hundred.

Values below ten reach Single-digit. Once that fails, values below one hundred reach Double-digit. The last branch means three or more digits, not exactly three. For -45, abs produces 45 and the second branch runs.

How is zero classified? Single-digit, because its magnitude is below ten.

What happens for -100? abs makes it 100, which reaches Multi-digit.

Quiz

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

Question 1

Why use abs first?

Pick an answer to check it.

Question 2

How is zero classified?

Pick an answer to check it.

Questions people ask

How is zero classified?

Single-digit, because its magnitude is below ten.

What happens for -100?

abs makes it 100, which reaches Multi-digit.

Why use abs first?

The sign is not a decimal digit.