geometric mean reference https en wikipedia orgwikigeometricmean geometric series reference https en wikipedia orgwikigeometricseries checking whether the input series is geometric series or not isgeometricseries2 4 8 true isgeometricseries3 6 12 24 true isgeometricseries1 2 3 false isgeometricseries0 0 3 false isgeometricseries traceback most recent call last valueerror input list must be a non empty list isgeometricseries4 traceback most recent call last valueerror input series is not valid valid series 2 4 8 return the geometric mean of series geometricmean2 4 8 3 9999999999999996 geometricmean3 6 12 24 8 48528137423857 geometricmean4 8 16 7 999999999999999 geometricmean4 traceback most recent call last valueerror input series is not valid valid series 2 4 8 geometricmean1 2 3 1 8171205928321397 geometricmean0 2 3 0 0 geometricmean traceback most recent call last valueerror input list must be a non empty list checking whether the input series is geometric series or not is_geometric_series 2 4 8 true is_geometric_series 3 6 12 24 true is_geometric_series 1 2 3 false is_geometric_series 0 0 3 false is_geometric_series traceback most recent call last valueerror input list must be a non empty list is_geometric_series 4 traceback most recent call last valueerror input series is not valid valid series 2 4 8 return the geometric mean of series geometric_mean 2 4 8 3 9999999999999996 geometric_mean 3 6 12 24 8 48528137423857 geometric_mean 4 8 16 7 999999999999999 geometric_mean 4 traceback most recent call last valueerror input series is not valid valid series 2 4 8 geometric_mean 1 2 3 1 8171205928321397 geometric_mean 0 2 3 0 0 geometric_mean traceback most recent call last valueerror input list must be a non empty list
def is_geometric_series(series: list) -> bool:
    
    if not isinstance(series, list):
        raise ValueError("Input series is not valid, valid series - [2, 4, 8]")
    if len(series) == 0:
        raise ValueError("Input list must be a non empty list")
    if len(series) == 1:
        return True
    try:
        common_ratio = series[1] / series[0]
        for index in range(len(series) - 1):
            if series[index + 1] / series[index] != common_ratio:
                return False
    except ZeroDivisionError:
        return False
    return True


def geometric_mean(series: list) -> float:
    
    if not isinstance(series, list):
        raise ValueError("Input series is not valid, valid series - [2, 4, 8]")
    if len(series) == 0:
        raise ValueError("Input list must be a non empty list")
    answer = 1
    for value in series:
        answer *= value
    return pow(answer, 1 / len(series))


if __name__ == "__main__":
    import doctest

    doctest.testmod()