In this simple exercise from CodeWars, you will build a function program that takes a value, integer and returns a list of its multiples up to another value, limit. If the 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.

Below is the solution, write down your own solution in the comment box.

def find_multiples(integer, limit): li = [] mul = 1 while(True): number = integer * mul mul += 1 if number <= limit: li.append(number) else: return li

The while loop will keep on running until the limit has been reached then the function will return the entire list.

Please follow and like us:

Please see this https://stackoverflow.com/questions/14553349/finding-multiples-of-a-number-in-python for vastly superior ways to write this code.

def find_multiples(integer, limit):

last = limit // integer

return [integer * i for i in range(last + 1)]