Check if All Digits are Distinct
Take a 3-digit number and check if all digits are distinct.
IntermediatePhase 1 - Level 3: Math and Number LogicExample 1 of 10
check-if-all-digits-are-distinct.py
1# Take 3-digit number2num = int(input("Enter a 3-digit number: "))34# Extract digits5digit1 = num // 1006digit2 = (num // 10) % 107digit3 = num % 1089# Check if all distinct10if digit1 != digit2 and digit2 != digit3 and digit1 != digit3:11 print("All digits are distinct")12else:13 print("Digits are not all distinct")
Output
Enter a 3-digit number: 123 All digits are distinct Enter a 3-digit number: 122 Digits are not all distinct
What's going on
Extract digits and compare them.
Key Concepts:
Extract hundreds, tens, and units digits
Compare all pairs: digit1 != digit2, digit2 != digit3, digit1 != digit3
All must be different for distinct digits
🔗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