Introduction
An arithmetic progression is a sequence of numbers in which each term is obtained by adding a constant value to the previous term. For example, 1, 3, 5, 7, 9 is an arithmetic progression with a common difference of 2. In this challenge, you will write a function that generates a list of numbers in the arithmetic progression starting with the given positive integer and up to the specified limit.
Arithmetic Progression
Write a function arithmetic_progression(n, lim) that takes in two positive integers n and lim and returns a list of numbers in the arithmetic progression starting with n and up to lim. The function should use range() and list() with the appropriate start, step, and end values to generate the list.
Input
- Two positive integers
nandlimwherenis the starting number andlimis the limit.
Output
- A list of numbers in the arithmetic progression starting with
nand up tolim.
def arithmetic_progression(n, lim):
return list(range(n, lim + 1, n))
arithmetic_progression(5, 25) ## [5, 10, 15, 20, 25]
Summary
In this challenge, you wrote a function that generates a list of numbers in the arithmetic progression starting with the given positive integer and up to the specified limit. You used range() and list() with the appropriate start, step, and end values to generate the list.