Absolute Difference Check
Take two numbers and determine if their absolute difference is < 10.
AdvancedPhase 1 - Level 5: Creative / Tricky Logical ScenariosExample 10 of 10
absolute-difference-check.py
1# Take two numbers2num1 = float(input("Enter first number: "))3num2 = float(input("Enter second number: "))45# Calculate absolute difference6diff = abs(num1 - num2)78# Check9if diff < 10:10 print(f"Absolute difference ({diff}) is less than 10")11else:12 print(f"Absolute difference ({diff}) is not less than 10")
Output
Enter first number: 15 Enter second number: 20 Absolute difference (5.0) is less than 10 Enter first number: 15 Enter second number: 30 Absolute difference (15.0) is not less than 10
What's going on
Calculate absolute difference and compare.
Key Concepts:
Use abs() to get absolute value
Calculate difference
Compare with threshold
🔗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