Python: Function to check whether a number is divisible by another number
Divisibility Tester
Write a Python function to check whether a number is divisible by another number. Accept two integer values from the user.
Sample Solution:
Python Code :
# Define a function named 'multiple' that takes two arguments, 'm' and 'n'.
def multiple(m, n):
# Check if 'm' is a multiple of 'n' by using the modulo operator.
# If the remainder is 0, return True, indicating 'm' is a multiple of 'n'.
# Otherwise, return False.
return True if m % n == 0 else False
# Call the 'multiple' function with different arguments and print the results.
print(multiple(20, 5)) # Check if 20 is a multiple of 5 and print the result.
print(multiple(7, 2)) # Check if 7 is a multiple of 2 and print the result.
Sample Output:
True False
Pictorial Presentation:

Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to check if a number is divisible by 2 and 3 simultaneously.
- Write a Python function to determine the highest power of a divisor that divides a number.
- Write a Python program to check if a number is divisible by all integers in a given range.
- Write a Python function to determine if a number is a multiple of another using bitwise operations.
Python Code Editor:
Previous: Write a Python program to find the location of Python module sources.
Next: Write a Python function to find the maximum and minimum numbers from a sequence of numbers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics