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 input2num = int(input("Enter a number: "))34# Check if divisible by both 3 and 55if 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 Truenum % 3 == 0 checks divisibility by 3num % 5 == 0 checks divisibility by 5Both must be True for the number to be divisible by both
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum