Skip to content

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.

def is_multiple_of_5_not_3(num):
    return num % 5 == 0 and num % 3 != 0

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:

Input
10
Output
True
Input
15
Output
False
Input
-25
Output
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

def is_multiple_of_5_not_3(num):
    return num % 5 == 0 and num % 3 != 0
def is_multiple_of_5_not_3(num):
    is_mult_of_5 = num % 5 == 0
    is_mult_of_3 = num % 3 == 0
    return is_mult_of_5 and not is_mult_of_3
is_multiple_of_5_not_3 = lambda num: num % 5 == 0 and num % 3 != 0

Key takeaways

01

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).

02

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.

03

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.