harmonic mean reference https en wikipedia orgwikiharmonicmean harmonic series reference https en wikipedia orgwikiharmonicseriesmathematics checking whether the input series is arithmetic series or not isharmonicseries 1 23 12 25 13 true isharmonicseries 1 23 25 13 false isharmonicseries1 2 3 false isharmonicseries12 13 14 true isharmonicseries25 210 215 220 225 true isharmonicseries4 traceback most recent call last valueerror input series is not valid valid series 1 23 2 isharmonicseries traceback most recent call last valueerror input list must be a non empty list isharmonicseries0 traceback most recent call last valueerror input series cannot have 0 as an element isharmonicseries1 2 0 6 traceback most recent call last valueerror input series cannot have 0 as an element return the harmonic mean of series harmonicmean1 4 4 2 0 harmonicmean3 6 9 12 5 759999999999999 harmonicmean4 traceback most recent call last valueerror input series is not valid valid series 2 4 6 harmonicmean1 2 3 1 6363636363636365 harmonicmean traceback most recent call last valueerror input list must be a non empty list checking whether the input series is arithmetic series or not is_harmonic_series 1 2 3 1 2 2 5 1 3 true is_harmonic_series 1 2 3 2 5 1 3 false is_harmonic_series 1 2 3 false is_harmonic_series 1 2 1 3 1 4 true is_harmonic_series 2 5 2 10 2 15 2 20 2 25 true is_harmonic_series 4 traceback most recent call last valueerror input series is not valid valid series 1 2 3 2 is_harmonic_series traceback most recent call last valueerror input list must be a non empty list is_harmonic_series 0 traceback most recent call last valueerror input series cannot have 0 as an element is_harmonic_series 1 2 0 6 traceback most recent call last valueerror input series cannot have 0 as an element return the harmonic mean of series harmonic_mean 1 4 4 2 0 harmonic_mean 3 6 9 12 5 759999999999999 harmonic_mean 4 traceback most recent call last valueerror input series is not valid valid series 2 4 6 harmonic_mean 1 2 3 1 6363636363636365 harmonic_mean traceback most recent call last valueerror input list must be a non empty list
def is_harmonic_series(series: list) -> bool:
    
    if not isinstance(series, list):
        raise ValueError("Input series is not valid, valid series - [1, 2/3, 2]")
    if len(series) == 0:
        raise ValueError("Input list must be a non empty list")
    if len(series) == 1 and series[0] != 0:
        return True
    rec_series = []
    series_len = len(series)
    for i in range(series_len):
        if series[i] == 0:
            raise ValueError("Input series cannot have 0 as an element")
        rec_series.append(1 / series[i])
    common_diff = rec_series[1] - rec_series[0]
    for index in range(2, series_len):
        if rec_series[index] - rec_series[index - 1] != common_diff:
            return False
    return True


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


if __name__ == "__main__":
    import doctest

    doctest.testmod()