Check if Divisible by Both 3 and 5

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

Logic BuildingBeginner
Logic Building
# Take a number as input
num = int(input("Enter a number: "))

# Check if divisible by both 3 and 5
if num % 3 == 0 and num % 5 == 0:
    print("Divisible by both 3 and 5")
else:
    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

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