Print All Factors
Print all factors of a number.
IntermediatePhase 2 - Level 3: Mathematical & Logical PatternsExample 6 of 13
print-all-factors.py
1# Take number2num = int(input("Enter a number: "))34# Print factors5print(f"Factors of {num}:")6for i in range(1, num + 1):7 if num % i == 0:8 print(i, end=" ")9print()
Output
Enter a number: 12 Factors of 12: 1 2 3 4 6 12
What's going on
Check each number from 1 to num.
Key Concepts:
Loop from 1 to num
Check if num % i == 0
If yes, i is a factor
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum