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

Numbers Divisible by 7

List multiples of seven inside an inclusive interval with Python. Students combine range boundaries, a remainder filter, and shared-line output formatting.

IntermediatePhase 2 - Level 3: Mathematical & Logical PatternsExample 3 of 13
numbers-divisible-by-7.py
1# Take range
2a = int(input("Enter a: "))
3b = int(input("Enter b: "))
4
5# Print divisible by 7
6print(f"Numbers divisible by 7 between {a} and {b}:")
7for i in range(a, b + 1):
8 if i % 7 == 0:
9 print(i, end=" ")
10print()

Output

Enter a: 10
Enter b: 50
Numbers divisible by 7 between 10 and 50:
14 21 28 35 42 49

In this one

  • Search an inclusive interval
  • Filter with modulo
  • Keep matching values in order

How it works

  1. 1

    Read a and b.

  2. 2

    Visit a through b and test remainder seven.

  3. 3

    Print qualifying values on one line.

Edge cases

Is zero a match if inside the interval?

Is zero a match if inside the interval?

Yes. Zero has remainder zero modulo seven.

What if a exceeds b?

What if a exceeds b?

No numbers are visited by this ascending range.

What's going on

The loop visits every integer from a through b. A value prints only when its remainder after division by seven is zero.

b + 1 makes the upper endpoint eligible. end keeps matching values together, and the final print ends the line. A reversed interval is not automatically reordered; an ascending range then contains no values.

Is zero a match if inside the interval? Yes. Zero has remainder zero modulo seven.

What if a exceeds b? No numbers are visited by this ascending range.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

Which test selects a multiple?

Pick an answer to check it.

Question 2

Is zero a match if inside the interval?

Pick an answer to check it.

Questions people ask

Is zero a match if inside the interval?

Yes. Zero has remainder zero modulo seven.

What if a exceeds b?

No numbers are visited by this ascending range.

Which test selects a multiple?

i % 7 == 0.