Pure Python implementation of Harmonic Series algorithm :param n_term: The last (nth) term of Harmonic Series :return: The Harmonic Series starting from 1 to last (nth) term Examples: >>> harmonic_series(5) ['1', '1/2', '1/3', '1/4', '1/5'] >>> harmonic_series(5.0) ['1'
(n_term: str)
| 13 | |
| 14 | |
| 15 | def harmonic_series(n_term: str) -> list: |
| 16 | """Pure Python implementation of Harmonic Series algorithm |
| 17 | |
| 18 | :param n_term: The last (nth) term of Harmonic Series |
| 19 | :return: The Harmonic Series starting from 1 to last (nth) term |
| 20 | |
| 21 | Examples: |
| 22 | >>> harmonic_series(5) |
| 23 | ['1', '1/2', '1/3', '1/4', '1/5'] |
| 24 | >>> harmonic_series(5.0) |
| 25 | ['1', '1/2', '1/3', '1/4', '1/5'] |
| 26 | >>> harmonic_series(5.1) |
| 27 | ['1', '1/2', '1/3', '1/4', '1/5'] |
| 28 | >>> harmonic_series(-5) |
| 29 | [] |
| 30 | >>> harmonic_series(0) |
| 31 | [] |
| 32 | >>> harmonic_series(1) |
| 33 | ['1'] |
| 34 | """ |
| 35 | if n_term == "": |
| 36 | return [] |
| 37 | series: list = [] |
| 38 | for temp in range(int(n_term)): |
| 39 | series.append(f"1/{temp + 1}" if series else "1") |
| 40 | return series |
| 41 | |
| 42 | |
| 43 | if __name__ == "__main__": |
no test coverage detected