# Lesson goal: Testing divisibility

Previous: Fermat's Last Theorem | Home | Next: Introduction

In a previous lesson, you used the % (or mod) operator to find the remainder one gets when two numbers are divided, say like a % b. If a remainder is ever zero, it means that b divides evenly into a, or a is divisible by b.

Try this (from Salkind, 1966): Use a for-loop and an if-statement to find the number of positive integers less than 1000 that are NOT divisible by either 5 or 7. To count, a number must not be simultaneously divisible by either 5 or 7.

# Now you try. Finish the code with % and an if statement that increases count if a given number is found.

Start with the code here that initializes the variable count to zero, then runs the variable num from 1 to 999 (these are positive numbers less than 1000). This will generate your test numbers. If you determine that num is not divisible by 5 and 7, then increase count by one. Dismiss.
Show a friend, family member, or teacher what you've done!