Part of the series

Several example codes

~1 min read • Updated Oct 8, 2025

Program Overview

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.


Python Code:


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}")

Sample Output for n = 4 and k = 3:


3  
33  
333  
3333  
Sum of the series: 3702

Step-by-Step Explanation:

- 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


Written & researched by Dr. Shahin Siami