This is a Python Program to print all integers that aren’t divisible by either 2 or 3 and lies between 1 and 50.
The program prints all integers that aren’t divisible by either 2 or 3 and lies between 1 and 50.
1. Use a for-loop ranging from 0 to 51.
2. Then use an if statement to check if the number isn’t divisible by both 2 and 3.
3. Print the numbers satisfying the condition.
4. Exit.
Here is source code of the Python Program to print all integers that aren’t divisible by either 2 or 3 and lies between 1 and 50. The program output is also shown below.
for i in range(0,51): if(i%2!=0&i%3!=0): print(i)
1. The for loop ranges from 0 to 50 (as 51 isn’t exclusive).
2. The expression within the if-statement checks if the remainder obtained when the number divided by 2 and 3 is one or not.
3. If the remainder isn’t equal to 0, the number isn’t divisible by either 2 and 3.
4. The number satisfying the condition is printed.
Case 1: 1 5 7 11 13 17 19 23 25 29 31 35 37 41 43 47 49
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Get Free Certificate of Merit in Python Programming
- Participate in Python Programming Certification Contest
- Become a Top Ranker in Python Programming
- Take Python Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Python Internship
- Buy Python Books
- Buy Information Technology Books
- Practice Programming MCQs
- Apply for Programming Internship