반응형
Description:
Create a function that checks if a number n is divisible by two numbers x AND y. All inputs are positive, non-zero digits.
Examples:
1) n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3
2) n = 12, x = 2, y = 6 => true because 12 is divisible by 2 and 6
3) n = 100, x = 5, y = 3 => false because 100 is not divisible by 3
4) n = 12, x = 7, y = 5 => false because 12 is neither divisible by 7 nor 5
Solution:
1. Check whether n is divisible by x and y, respectively.
2. Returns a boolean value.
def is_divisible(n,x,y):
return bool(not n%x and not n%y)
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Invert values (0) | 2022.03.27 |
---|---|
How many pages in a book? (0) | 2022.03.26 |
Find the divisors! (0) | 2022.03.24 |
Sum of Digits / Digital Root (0) | 2022.03.23 |
Dashatize it (0) | 2022.03.22 |