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.
1# Take number2num = abs(int(input("Enter a number: ")))34# Check digit count5if 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
Apply abs to the converted integer.
- 2
Test magnitude below ten, then below one hundred.
- 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.
๐Related Content
- ๐
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- ๐
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- ๐ป
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum