Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

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.

BeginnerPhase 2 - Level 1: Basic LoopingExample 12 of 14
print-multiples-of-5-up-to-n.py
1# Take n as input
2n = int(input("Enter n: "))
3
4# Print multiples of 5
5print("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. 1

    Print the multiples heading.

  2. 2

    Visit five through n with step five.

  3. 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.