Write a program to calculate the sum of series up to n term. For example, if n =5 the series will become 2 + 22 + 222 + 2222 + 22222 = 24690
n =5
Given:
# number of terms n = 5
Expected output:
24690
Solution:
n = 5 # first number of sequence start = 2 sum_seq = 0 # run loop n times for i in range(0, n): print(start, end="+") sum_seq += start # calculate the next term start = start * 10 + 2 print("\nSum of above series is:", sum_seq)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Solution:
need an explanation for this answer? contact us directly to get an explanation for this answer