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]
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)
Comments
Leave a comment