반응형
Task:
Write a function that accepts two integers and returns the remainder of dividing the larger value by the smaller value.
Division by zero should return an empty value.
Examples:
n = 17 m = 5 result = 2 (remainder of `17 / 5`) n = 13 m = 72 result = 7 (remainder of `72 / 13`) n = 0 m = -1 result = 0 (remainder of `0 / -1`) n = 0 m = 1 result - division by zero (refer to the specifications on how to handle this in your language)
Solution:
def remainder(a, b): min_num, max_num = sorted([a, b]) if min_num == 0: return None if max_num == 0: return 0 return max_num % min_num
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1005. Palindrome Strings (0) | 2022.10.05 |
---|---|
1004. Keep up the hoop (0) | 2022.10.04 |
1002. Twice as old (0) | 2022.10.03 |
1001. Hello, Name or World! (0) | 2022.10.02 |
0930. Count of positives, sum of negatives (0) | 2022.09.30 |