range and Counting Loops
~8 mincode completion
Write multiples_of(n, count) that returns a list of the first count positive multiples of n.
multiples_of(3, 4) returns [3, 6, 9, 12]. Note it starts at n, not at 0.
Examples
The first four multiples of 3 start at 3, not 0
- Input
- multiples_of(3, 4)
- Output
- [3, 6, 9, 12]
Multiples of 5 with a different count
- Input
- multiples_of(5, 3)
- Output
- [5, 10, 15]
Asking for one multiple returns just n
- Input
- multiples_of(7, 1)
- Output
- [7]
Hints
Hint 1
Build the result up as you go, then return it.
Hint 2
Watch for this: started at zero.
Requirements
n: the number to multiplycount: how many multiples to produceReturn a list like [n, 2n, 3n, ...] with count items.
Constraints
Standard library only, no imports required
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~8 min
••••••
3 employers weight this skill
2 frontier labs, 1 AI product company. Top match scores 80.
Python
def multiples_of(n, count):
"""
Build the first count positive multiples of n.
Args:
n: the number to multiply
count: how many multiples to produce
Returns:
A list like [n, 2n, 3n, ...] with count items.
"""
# YOUR CODE HERE
pass