Part of the series

Several example codes

~1 min read • Updated Oct 4, 2025

Program Overview

This Python program reads two integers from the user and checks whether each number is divisible by the other.
If both a % b == 0 and b % a == 0 are true, it prints "Yes".
Otherwise, it prints "No".


Python Code:


# Read two numbers from user
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))

# Check mutual divisibility
if a % b == 0 and b % a == 0:
    print("Yes")
else:
    print("No")

Sample Output:


Enter the first number: 5  
Enter the second number: 5  
Yes

Enter the first number: 4  
Enter the second number: 2  
No

Step-by-Step Explanation:

- The program uses the modulo operator % to check for zero remainders
- a % b == 0 means a is divisible by b
- b % a == 0 means b is divisible by a
- Both conditions must be true for the output to be "Yes"
- If either condition fails, the output is "No"


Written & researched by Dr. Shahin Siami