Answer to Question #337778 in Python for jamil

Question #337778

Write a Python program that reads a number and finds the sum of the series

of 1 + 33 + 111 + 3333 +....+N terms. Then it puts the reverse digit of the sum to a list and prints it. [Cannot use built-in reverse() or reversed()]

Sample Input 1:

5

Sample Output 1:

Sum of series: 14589 Reverse sum of series in list: [9, 8, 5, 4, 1]


1
Expert's answer
2022-05-06T15:36:32-0400
n = int(input())
s = 0
for i in range(n):
	indx = i%2
	if indx == 0:
		s += int(''.join(['1' for _ in range(i+1)]))
	else:
		s += int(''.join(['3' for _ in range(i+1)]))
res = []
for num in str(s)[::-1]:
	res.append(int(num))
print(res)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS