Check if Number in Range
Check if a number lies within the range [100, 999].
IntermediatePhase 1 - Level 3: Math and Number LogicExample 8 of 10
check-if-number-in-range.py
1# Take number2num = int(input("Enter a number: "))34# Check range5if 100 <= num <= 999:6 print("Number is in range [100, 999]")7else:8 print("Number is not in range [100, 999]")
Output
Enter a number: 500 Number is in range [100, 999] Enter a number: 50 Number is not in range [100, 999]
What's going on
Use range check with <= operator.
Key Concepts:
Range [100, 999]: 100 <= num <= 999
Inclusive of both endpoints
Use chained comparison
🔗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