easy +10 pts

Is divisible by?

Write a function that checks if one integer divides another exactly.

Implement the function `is_divisible_by(a, b)` that returns `True` if `a` is divisible by `b` exactly (i.e., the remainder of dividing `a` by `b` is `0`) and `False` otherwise. **Important rules:** - If `b == 0`, division by zero is undefined, so the function must return `False`. - Negative divisors are allowed. For example, `10` is divisible by `-5` because `10 % -5 == 0`. - Zero is divisible by any non-zero integer (e.g., `0` is divisible by `7`). - Both arguments are integers. Your function should handle all these cases without raising an exception.

Constraints

Input: Two integers `a` and `b`. Time complexity: O(1). Space complexity: O(1).

Example

```python
>>> is_divisible_by(10, 2)
True
>>> is_divisible_by(10, 3)
False
>>> is_divisible_by(10, 0)
False
>>> is_divisible_by(-10, 5)
True
```
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use the modulo operator `%` to check the remainder.
First check whether `b` is zero to avoid a division error.
The remainder can be negative in Python, so compare to 0 carefully—actually `%` works naturally here.
Test with negative divisors and zero dividend.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.