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.
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
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.
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.
You must be logged in to post a comment.