(Find numbers divisible by 5 and 6) Write a program that displays, ten numbers per line, all the numbers from 100 to 1,000 that are divisible by 5 and 6. The numbers are separated by exactly one space.
Find numbers divisible by 5 and 6 program code:
# Initialize a counter for the number of divisible numbers
count = 0
# Iterate over the range from 100 to 1000 (inclusive)
for number in range(100, 1001):
# Check if the number is divisible by both 5 and 6
if number % 5 == 0 and number % 6 == 0:
# Print the number followed by a space
print(number, end=" ")
count += 1
# Check if ten numbers have been printed in the current line
if count % 10 == 0:
# Print a new line
print()
# Print a final new line if the last line is not complete
if count % 10 != 0:
print()
Executed Output:
120 150 180 210 240 270 300 330 360 390
420 450 480 510 540 570 600 630 660 690
720 750 780 810 840 870 900 930 960 990