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:
andoperator requires both conditions to be Truenum % 3 == 0checks divisibility by 3num % 5 == 0checks divisibility by 5- Both must be True for the number to be divisible by both