48.5k views
5 votes
write a program in python to print all the numbers from 1 to 1000 that are not divisible by 2,3,5,7,11

1 Answer

4 votes

Final answer:

To print all numbers from 1 to 1000 not divisible by 2, 3, 5, 7, and 11 in Python, use a for loop to iterate over the numbers and an if statement to check for non-divisibility by these numbers, then print those that meet the criteria.

Step-by-step explanation:

To write a program in Python that prints all the numbers from 1 to 1000 that are not divisible by 2, 3, 5, 7, and 11, you can use a loop to iterate through each number and conditional statements to check divisibility.

Here is an example of how such a program might look:

for number in range(1, 1001):
if number % 2 != 0 and number % 3 != 0 and number % 5 != 0 and number % 7 != 0 and number % 11 != 0:
print(number)
This program uses a for loop to go through each number from 1 to 1000. The if statement inside the loop checks whether the current number is not divisible by 2, 3, 5, 7, or 11 using the modulo operator (%). If the number is not divisible by any of those, it gets printed out.
User YuQing Zhang
by
8.4k points