Arithmetic Progression Generator | Challenge

PythonPythonBeginner
Practice Now

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.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("`Python`")) -.-> python/BasicConceptsGroup(["`Basic Concepts`"]) python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"]) python(("`Python`")) -.-> python/FunctionsGroup(["`Functions`"]) python(("`Python`")) -.-> python/PythonStandardLibraryGroup(["`Python Standard Library`"]) python/BasicConceptsGroup -.-> python/comments("`Comments`") python/BasicConceptsGroup -.-> python/variables_data_types("`Variables and Data Types`") python/DataStructuresGroup -.-> python/lists("`Lists`") python/DataStructuresGroup -.-> python/tuples("`Tuples`") python/FunctionsGroup -.-> python/function_definition("`Function Definition`") python/PythonStandardLibraryGroup -.-> python/data_collections("`Data Collections`") python/FunctionsGroup -.-> python/build_in_functions("`Build-in Functions`") subgraph Lab Skills python/comments -.-> lab-13055{{"`Arithmetic Progression Generator | Challenge`"}} python/variables_data_types -.-> lab-13055{{"`Arithmetic Progression Generator | Challenge`"}} python/lists -.-> lab-13055{{"`Arithmetic Progression Generator | Challenge`"}} python/tuples -.-> lab-13055{{"`Arithmetic Progression Generator | Challenge`"}} python/function_definition -.-> lab-13055{{"`Arithmetic Progression Generator | Challenge`"}} python/data_collections -.-> lab-13055{{"`Arithmetic Progression Generator | Challenge`"}} python/build_in_functions -.-> lab-13055{{"`Arithmetic Progression Generator | Challenge`"}} end

Arithmetic Progression

Problem

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.

Example

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.

Other Python Tutorials you may like