Check if One Number is Multiple of Other
Check if one of two given numbers is a multiple of the other.
IntermediatePhase 1 - Level 2: Nested If & Multiple ConditionsExample 4 of 10
check-if-one-number-is-multiple-of-other.py
1# Take two numbers as input2num1 = int(input("Enter first number: "))3num2 = int(input("Enter second number: "))45# Check if one is multiple of other6if num1 % num2 == 0:7 print(f"{num1} is a multiple of {num2}")8elif num2 % num1 == 0:9 print(f"{num2} is a multiple of {num1}")10else:11 print("Neither is a multiple of the other")
Output
Enter first number: 15 Enter second number: 5 15 is a multiple of 5 Enter first number: 7 Enter second number: 3 Neither is a multiple of the other
What's going on
Check both directions: num1 % num2 and num2 % num1.
Key Concepts:
If num1 % num2 == 0, num1 is multiple of num2
If num2 % num1 == 0, num2 is multiple of num1
Check both possibilities
🔗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