141k views
2 votes
Write a program fragment, using loop(s), to print all numbers that are divisible by 6 between 1 and 1000, inclusive. Do not worry about spaces.

User Oillio
by
7.9k points

1 Answer

2 votes

Final answer:

The question requires a program fragment to print numbers between 1 and 1000 that are divisible by 6. A loop iterates through each number, uses modulus to check divisibility, and prints each divisible number.

Step-by-step explanation:

A student has asked for a program fragment using loops to print all numbers divisible by 6 between 1 and 1000, inclusive. Here's how you can do this in Python:

for number in range(1, 1001):
if number % 6 == 0:
print(number)

This loop iterates through each number from 1 to 1000 and checks whether each number is divisible by 6 using the modulus operator (%). If the result of the modulus operation (number % 6) is 0, it means the number is divisible by 6, and the program then prints it.

User Maxim Firsoff
by
7.9k points