Skip to content

Commit a2c7d89

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6d6f7f2 commit a2c7d89

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

maths/sum_of_geometric_progression.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from typing import Union
22
# ... other imports ...
33

4+
45
def sum_of_geometric_progression(
56
# FIX: Changed 'int' to 'Union[int, float]' to allow non-integer terms/ratios
6-
first_term: Union[int, float], common_ratio: Union[int, float], num_of_terms: int
7+
first_term: Union[int, float],
8+
common_ratio: Union[int, float],
9+
num_of_terms: int,
710
) -> float:
811
"""
912
Return the sum of n terms in a geometric progression.
@@ -23,7 +26,7 @@ def sum_of_geometric_progression(
2326
-341.0
2427
>>> sum_of_geometric_progression(1, 2, -10)
2528
-0.9990234375
26-
29+
2730
# NEW DOCTEST to validate float inputs
2831
>>> sum_of_geometric_progression(0.5, 2, 3)
2932
3.5
@@ -34,4 +37,4 @@ def sum_of_geometric_progression(
3437

3538
# Formula for finding sum of n terms of a GeometricProgression
3639
# Note: Python's standard float arithmetic handles this correctly for the fix.
37-
return (first_term / (1 - common_ratio)) * (1 - common_ratio**num_of_terms)
40+
return (first_term / (1 - common_ratio)) * (1 - common_ratio**num_of_terms)

0 commit comments

Comments
 (0)