Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion maths/sum_of_geometric_progression.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def sum_of_geometric_progression(
if common_ratio == 1:
# Formula for sum if common ratio is 1
return num_of_terms * first_term
if first_term == 0:
return 0.0

# Formula for finding sum of n terms of a GeometricProgression
return (first_term / (1 - common_ratio)) * (1 - common_ratio**num_of_terms)
return first_term * (1 - common_ratio**num_of_terms) / (1 - common_ratio)