Print Multiples of 5 Up to N

Print all multiples of 5 from 5 to n.

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

What's going on

Use range with step 5 to get multiples.

Key Concepts:

range(5, n+1, 5) gives multiples of 5
Step size 5 skips non-multiples
Efficient way to get multiples