Checking Multiples with Lambda

Write a lambda function that checks if a number is a multiple of another number.

Example 1:

Input: 10, 5
Output: True

Example 2:

Input: 7, 3
Output: False

Use a lambda function and the modulus operator.

# Define the lambda function
is_multiple = lambda x, y: x % y == 0

# Test the function
print(is_multiple(10, 5)) # Output: True
print(is_multiple(7, 3)) # Output: False

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!