Print Multiples of 5 Up to N
Print multiples of five up to a chosen limit in Python. Beginners follow a stepped range and learn how end changes spacing while a final print ends the line.
1# Take n as input2n = int(input("Enter n: "))34# Print multiples of 55print("Multiples of 5:")6for i in range(5, n + 1, 5):7 print(i, end=" ")8print()
Output
Enter n: 25 Multiples of 5: 5 10 15 20 25
In this one
- Generate multiples by stepping
- Control print separators
- End a shared output line
How it works
- 1
Print the multiples heading.
- 2
Visit five through n with step five.
- 3
Print terms with spaces and finish with a newline.
Edge cases
What if n is four?
What if n is four?
The heading prints, but there are no numeric terms.
Is zero listed?
Is zero listed?
No. The range begins at five.
What's going on
Starting at five and advancing by five directly generates the required multiples. No modulo check is needed because every visited value is already a multiple.
print(i, end=" ") leaves a space rather than a newline after each number. The final empty print ends the row. For n equal to twelve, only five and ten appear beneath the heading; the endpoint need not itself be a multiple.
What if n is four? The heading prints, but there are no numeric terms.
Is zero listed? No. The range begins at five.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Why use a final print()?
Pick an answer to check it.
Question 2
What if n is four?
Pick an answer to check it.
Questions people ask
What if n is four?
The heading prints, but there are no numeric terms.
Is zero listed?
No. The range begins at five.
Why use a final print()?
To end the shared output line.
๐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