The problem
Create a perform with two arguments that can return an array of the primary (n) multiples of (x).
Assume each the given quantity and the variety of instances to rely will probably be optimistic numbers larger than 0.
Return the outcomes as a listing.
Examples
count_by(1,10) #ought to return [1,2,3,4,5,6,7,8,9,10]
count_by(2,5) #ought to return [2,4,6,8,10]
The answer in Python code
Choice 1:
def count_by(x, n):
out = []
for i in vary(n):
out.append(x*(i+1))
return out
Choice 2:
def count_by(x, n):
return vary(x, x * n + 1, x)
Choice 3:
def count_by(x, n):
return [i * x for i in range(1, n + 1)]
Take a look at circumstances to validate our answer
import check
from answer import count_by
@check.describe("Mounted Checks")
def basic_tests():
@check.it("Mounted exams")
def fixed_tests():
check.assert_equals(count_by(1, 5), [1, 2, 3, 4, 5])
check.assert_equals(count_by(2, 5), [2, 4, 6, 8, 10])
check.assert_equals(count_by(3, 5), [3, 6, 9, 12, 15])
check.assert_equals(count_by(50, 5), [50, 100, 150, 200, 250])
check.assert_equals(count_by(100, 5), [100, 200, 300, 400, 500])