num_theory.arithmetic_progression

Functions

arithmetic_progression(a, d, n[, compute_sum, nth_term])

Generate terms of an arithmetic progression (AP), compute the nth term, or calculate the sum of the first n terms.

Module Contents

num_theory.arithmetic_progression.arithmetic_progression(a, d, n, compute_sum=False, nth_term=False)[source]

Generate terms of an arithmetic progression (AP), compute the nth term, or calculate the sum of the first n terms.

Parameters:
  • a (float) – The first term of the AP.

  • d (float) – The common difference between consecutive terms.

  • n (int) – The number of terms, the term to compute, or the term index.

  • compute_sum (bool, optional) – If True, computes the sum of the first n terms. Default is False.

  • nth_term (bool, optional) – If True, computes the nth term of the AP instead of generating terms. Default is False.

Returns:

  • If compute_sum and nth_term are both False, returns a list of the first n terms of the AP.

  • If nth_term is True, returns the nth term as a float.

  • If compute_sum is True, returns the sum of the first n terms as a float.

  • If both nth_term and compute_sum is True, it will return the nth term as a float.

Return type:

list or float

Examples

>>> arithmetic_progression(a=2, d=3, n=5)
[2, 5, 8, 11, 14]
>>> arithmetic_progression(a=2, d=3, n=5, compute_sum=True)
40.0
>>> arithmetic_progression(a=2, d=3, n=5, nth_term=True)
14
>>> arithmetic_progression(a=1, d=2, n=5, nth_term=True)
9