Arithmetic Progression Generator

Beginner

This tutorial is from open-source community. Access the source code

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 n and lim where n is the starting number and lim is the limit.

Output

  • A list of numbers in the arithmetic progression starting with n and up to lim.
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.