this is a pure python implementation of the geometric series algorithm https en wikipedia orgwikigeometricseries run the doctests with the following command python3 m doctest v geometricseries py or python m doctest v geometricseries py for manual testing run python3 geometricseries py pure python implementation of geometric series algorithm param nthterm the last term nth term of geometric series param startterma the first term of geometric series param commonratior the common ratio between all the terms return the geometric series starting from first term a and multiple of common ration with first term with increase in power till last term nth term examples geometricseries4 2 2 2 4 0 8 0 16 0 geometricseries4 0 2 0 2 0 2 0 4 0 8 0 16 0 geometricseries4 1 2 1 2 1 2 1 4 41 9 261000000000001 19 448100000000004 geometricseries4 2 2 2 4 0 8 0 16 0 geometricseries4 2 2 2 4 0 8 0 16 0 geometricseries4 2 2 geometricseries0 100 500 geometricseries1 1 1 1 geometricseries0 0 0 pure python implementation of geometric series algorithm param nth_term the last term nth term of geometric series param start_term_a the first term of geometric series param common_ratio_r the common ratio between all the terms return the geometric series starting from first term a and multiple of common ration with first term with increase in power till last term nth term examples geometric_series 4 2 2 2 4 0 8 0 16 0 geometric_series 4 0 2 0 2 0 2 0 4 0 8 0 16 0 geometric_series 4 1 2 1 2 1 2 1 4 41 9 261000000000001 19 448100000000004 geometric_series 4 2 2 2 4 0 8 0 16 0 geometric_series 4 2 2 2 4 0 8 0 16 0 geometric_series 4 2 2 geometric_series 0 100 500 geometric_series 1 1 1 1 geometric_series 0 0 0
from __future__ import annotations


def geometric_series(
    nth_term: float,
    start_term_a: float,
    common_ratio_r: float,
) -> list[float]:
    
    if not all((nth_term, start_term_a, common_ratio_r)):
        return []
    series: list[float] = []
    power = 1
    multiple = common_ratio_r
    for _ in range(int(nth_term)):
        if not series:
            series.append(start_term_a)
        else:
            power += 1
            series.append(float(start_term_a * multiple))
            multiple = pow(float(common_ratio_r), power)
    return series


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    nth_term = float(input("Enter the last number (n term) of the Geometric Series"))
    start_term_a = float(input("Enter the starting term (a) of the Geometric Series"))
    common_ratio_r = float(
        input("Enter the common ratio between two terms (r) of the Geometric Series")
    )
    print("Formula of Geometric Series => a + ar + ar^2 ... +ar^n")
    print(geometric_series(nth_term, start_term_a, common_ratio_r))