S1Q1 · Check If Multiple of 5 but Not 3¶
⚡ Quick Reference
Function: is_multiple_of_5_not_3(num: int) -> bool
Core idea: check both divisibility conditions in one expression.
Key rules:
- Multiple of 5: num % 5 == 0
- NOT a multiple of 3: num % 3 != 0
- Both must hold - use and
- Works for negative numbers too (Python % is always non-negative for positive divisors)
Problem Statement¶
Problem
Write a function is_multiple_of_5_not_3(num) that returns True if num is divisible by 5 but not by 3.
Examples:
10
True
15
False
-25
True
Tracing all examples¶
num |
num % 5 |
Multiple of 5? | num % 3 |
Multiple of 3? | Result |
|---|---|---|---|---|---|
| 10 | 0 ✅ | Yes | 1 | No | True |
| 25 | 0 ✅ | Yes | 1 | No | True |
| -50 | 0 ✅ | Yes | 1 | No | True |
| 15 | 0 ✅ | Yes | 0 | Yes ❌ | False |
| 9 | 4 ❌ | No | - | - | False |
| 12 | 2 ❌ | No | - | - | False |
| -25 | 0 ✅ | Yes | 2 | No | True |
Solution approaches¶
Key takeaways¶
Two conditions combined with and
num % 5 == 0 and num % 3 != 0 - both must be true. Short-circuit and skips the second check if the first already fails (not a multiple of 5).
Works for negatives - Python % is non-negative
In Python, -25 % 5 == 0 and -25 % 3 == 2. The modulo operator always returns a non-negative result when the divisor is positive, so no special handling is needed for negative inputs.
15 is the classic trap - multiple of both
15 is divisible by both 5 and 3 (it's a multiple of 15). The num % 3 != 0 condition correctly excludes it. Always check both conditions explicitly.