Python Example – Write a Python program to print the length of the series

(Python Example for Citizen Data Scientist & Business Analyst)

 

Write a Python program to print the length of the series and the series from the given 3rd term, 3rd last term and the sum of a series.

Sample Data:
Input third term of the series: 3
Input 3rd last term: 3
Sum of the series: 15
Length of the series: 5
Series:
1 2 3 4 5

 

Sample Solution:

Python Code:

tn = int(input("Input third term of the series:"))
tltn = int(input("Input 3rd last term:"))
s_sum = int(input("Sum of the series:"))
n = int(2*s_sum/(tn+tltn))
print("Length of the series: ",n)


if n-5==0:
  d = (s_sum-3*tn)//6
else:
  d = (tltn-tn)/(n-5)

a = tn-2*d
j = 0
print("Series:")
for j in range(n-1):
  print(int(a),end=" ")
  a+=d
print(int(a),end=" ")

Sample Output:

Input third term of the series: 3
Input 3rd last term: 6
Sum of the series: 36
Length of the series:  8
Series:
1 2 3 4 5 6 7 8 

 

More Sample Output:

Input third term of the series: 3
Input 3rd last term: 3
Sum of the series: 15
Length of the series:  5
Series:
1 2 3 4 5

 

Write a Python program to print the length of the series

 

Sign up to get end-to-end “Learn By Coding” example.


Portfolio Projects for Aspiring Data Scientists: Tabular Text & Image Data Analytics as well as Time Series Forecasting in Python & R @ https://wacamlds.podia.com/portfolio-projects-for-aspiring-data-scientists-end-to-end-applied-machine-learning-solutions-in-python-r

 

 


Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.