Print All Factors
Print all positive factors of an positive integer with Python. Students trace an inclusive divisor scan and distinguish factors from multiples and remainders.
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
In this one
- Define positive factors
- Include num itself
- Format a filtered sequence
How it works
- 1
Visit candidates one through num.
- 2
Print a candidate if num % i is zero.
- 3
End the shared line after the search.
Edge cases
Is num itself listed?
Is num itself listed?
Yes. Every positive integer divides itself.
What happens for a negative input?
What happens for a negative input?
This ascending range prints no factors.
What's going on
A factor divides num with remainder zero. The loop tries every candidate from one through num, including the number itself.
For six, the printed candidates are one, two, three, and six. The values share a line because print uses end with a space. This is a direct search rather than an optimized factor-pair method; it makes one divisibility test per candidate.
Is num itself listed? Yes. Every positive integer divides itself.
What happens for a negative input? This ascending range prints no factors.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which values are factors of six?
Pick an answer to check it.
Question 2
Is num itself listed?
Pick an answer to check it.
Questions people ask
Is num itself listed?
Yes. Every positive integer divides itself.
What happens for a negative input?
This ascending range prints no factors.
Which values are factors of six?
1, 2, 3, 6.
๐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