This Python program reads two values from the user: n (number of terms) and k (a digit).
It then generates a series where each term is formed by repeating the digit k one more time than the previous term:
k + kk + kkk + ...
Each term is printed, and the final sum of all terms is displayed.
n = int(input("Enter number of terms (n): "))
k = input("Enter digit (k): ")
total = 0
term = ""
for i in range(1, n + 1):
term += k
print(term)
total += int(term)
print(f"Sum of the series: {total}")
3
33
333
3333
Sum of the series: 3702
- The digit k is treated as a string so it can be repeated
- In each iteration, k is appended to the previous term
- The term is converted to an integer and added to the total
- The final sum is printed after all terms are generated