Check if Divisible by Both 3 and 5

Check if a number is divisible by both 3 and 5.

BeginnerPhase 1 - Level 1: Simple ConditionsExample 4 of 10
check-if-divisible-by-both-3-and-5.py
1# Take a number as input
2num = int(input("Enter a number: "))
3
4# Check if divisible by both 3 and 5
5if num % 3 == 0 and num % 5 == 0:
6 print("Divisible by both 3 and 5")
7else:
8 print("Not divisible by both 3 and 5")

Output

Enter a number: 15
Divisible by both 3 and 5

Enter a number: 9
Not divisible by both 3 and 5

What's going on

Use the AND operator to check multiple conditions.

Key Concepts:

and operator requires both conditions to be True
num % 3 == 0 checks divisibility by 3
num % 5 == 0 checks divisibility by 5
Both must be True for the number to be divisible by both