Count Numbers Divisible by 7 but Not 5

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

Logic BuildingAdvanced
Logic Building
# Count numbers
count = 0
for num in range(1, 501):
    if num % 7 == 0 and num % 5 != 0:
        count += 1

print(f"Count: {count}")

Output

Count: 57

Check both conditions with AND.

Key Concepts:

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