How to Find Sum of Series in Python

Here’s a Python program that calculates the sum of geometric progression series. For instance, 1+11+111+111 and so on. For loop and Range function, you can use to write a script for this.

Python series sum

Geometric progression

This script will work for the GP series for any numeric number. The generalized input is n+nn+nnn+nnnn+ and so on.

Python knowledge applies

  • The range function decides how man terms sends to for loop
  • The for loop process the terms till all the numbers of range function
  • The print function displays total all the numbers present in this series.

Python script to calculate series sum

Python script to calculate series sum

Output

You can see the sum of all the terms in the output. In our case, I have hard-coded the number of terms as ‘5’. You can further improve this by asking for user input from the terminal. You need to use, for this, the input() function.

Result of Python script that calculates series sum

Here, first, you can see displays for all the series terms. Secondly, you can see the total of all the terms. It is a tricky python question. Must know how to write this logic before your interviews.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.