Numbers Divisible by 7

Print numbers between a and b divisible by 7.

Logic BuildingIntermediate
Logic Building
# Take range
a = int(input("Enter a: "))
b = int(input("Enter b: "))

# Print divisible by 7
print(f"Numbers divisible by 7 between {a} and {b}:")
for i in range(a, b + 1):
    if i % 7 == 0:
        print(i, end=" ")
print()

Output

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

Check each number in range for divisibility.

Key Concepts:

  • Loop through range a to b
  • Check if divisible by 7 using modulo
  • Print if condition met