From 885a3b995b80fb383467493695252554b2fe421b Mon Sep 17 00:00:00 2001 From: sdas-19 Date: Fri, 16 Oct 2026 07:48:22 +0530 Subject: [PATCH] fix(maths): validate input parameters and add doctests for harmonic progression --- maths/sum_of_harmonic_series.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index 9e0d6b19b95a..06800cda11a8 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -12,7 +12,19 @@ def sum_of_harmonic_progression( 0.75 >>> sum_of_harmonic_progression(1 / 5, 5, 5) 0.45666666666666667 + >>> sum_of_harmonic_progression(0,2,5) + Traceback (most recent call last): + ... + ValueError: first_term cannot be zero + >>> sum_of_harmonic_progression(1/2,2,0) + Traceback (most recent call last): + ... + ValueError: number_of_terms must be greater than zero """ + if first_term == 0: + raise ValueError("first_term cannot be zero") + if number_of_terms <= 0: + raise ValueError("number_of_terms must be greater than zero") arithmetic_progression = [1 / first_term] first_term = 1 / first_term for _ in range(number_of_terms - 1):