CoursesCSS StudioExamplesGATECompaniesPrepMentora
Programs/Logic building/Phase 2 - Level 5: Logical Loop Combinations

2 / 12

Next
1. Numbers with Even Digit Sum2. Count Numbers Divisible by 7 but Not 53. All Palindrome Numbers 1-5004. Numbers with Digit Sum Multiple of 35. Smallest & Largest Digit6. Numbers with Even 1s in Binary7. Print i*i Pattern8. Factorial of Each Number 1-N9. Sum of Odd & Even Digits Separately10. Sum with Continue (Skip 0)11. Sum of Squares of Even Numbers12. Count Primes in Range

Phase 2 - Level 5: Logical Loop Combinations

  1. 01Numbers with Even Digit Sum
  2. 02Count Numbers Divisible by 7 but Not 5
  3. 03All Palindrome Numbers 1-500
  4. 04Numbers with Digit Sum Multiple of 3
  5. 05Smallest & Largest Digit
  6. 06Numbers with Even 1s in Binary
  7. 07Print i*i Pattern
  8. 08Factorial of Each Number 1-N
  9. 09Sum of Odd & Even Digits Separately
  10. 10Sum with Continue (Skip 0)
  11. 11Sum of Squares of Even Numbers
  12. 12Count Primes in Range

Count Numbers Divisible by 7 but Not 5

Count numbers 1-500 divisible by 7 but not 5.

AdvancedPhase 2 - Level 5: Logical Loop CombinationsExample 2 of 12
count-numbers-divisible-by-7-but-not-5.py
1# Count numbers
2count = 0
3for num in range(1, 501):
4 if num % 7 == 0 and num % 5 != 0:
5 count += 1
6
7print(f"Count: {count}")

Output

Count: 57

What's going on

Check both conditions with AND.

Key Concepts:

Divisible by 7: num % 7 == 0
Not divisible by 5: num % 5 != 0
Count matching numbers

🔗Related Content

  • 📖

    Phase 2 - Learn Concepts

    Review Phase 2 concepts and explanations

  • 📝

    Phase 2 - Quiz

    Test your Phase 2 understanding with quiz questions

  • 💻

    Phase 2 - All Practice Problems

    Explore all practice problems for Phase 2

  • 🎓

    Master Your Logic Building - Complete Course

    Browse all phases and tutorials

  • 🧠

    Logic Building Overview

    Learn about the complete logic building curriculum

PreviousNumbers with Even Digit SumNextAll Palindrome Numbers 1-500

On this page

CodeOutputExplanation
Up nextAll Palindrome Numbers 1-500
Schoolabe

Learn, Practice, Ace Coding

ExamplesCompaniesTutorialsCSS StudioDSA VisualizersQuizInterview PrepMentoraCareer QuestGATE CS prepGATE CS 2027 study planJob ReadyInternships
AboutContactCareersAffiliate programBlog
DocumentationAPI ReferenceCommunitySupport
Privacy PolicyTermsRefund PolicyCookie Policy

© 2026 Schoolabe