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.
1# Take range2a = int(input("Enter a: "))3b = int(input("Enter b: "))45# Print divisible by 76print(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
Read a and b.
- 2
Visit a through b and test remainder seven.
- 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.
๐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