나는 이렇게 학습한다/Algorithm & SQL

1014. Find Multiples of a Number

daco2020 2022. 10. 14. 22:56
반응형

In this simple exercise, you will build a program that takes a value, integer , and returns a list of its multiples up to another value, limit . If limit is a multiple of integer, it should be included as well. There will only ever be positive integers passed into the function, not consisting of 0. The limit will always be higher than the base.

For example, if the parameters passed are (2, 6), the function should return [2, 4, 6] as 2, 4, and 6 are the multiples of 2 up to 6.

If you can, try writing it in only one line of code.



Solution:

def find_multiples(integer, limit):
    return [i*integer for i in range(1, limit//integer+1)]

Other Solution:

def find_multiples(integer, limit):
    return list(range(integer, limit+1, integer))


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

1016. Multiplication table for number  (0) 2022.10.17
1015. simple calculator  (0) 2022.10.15
1013. Area or Perimeter  (0) 2022.10.13
1012. All Star Code Challenge #18  (0) 2022.10.12
1011. Square(n) Sum  (0) 2022.10.11