Suppose we have a number n. We have to print a triangle with n rows and each line will hold line number i, i number of times.
So, if the input is like n = 5, then the output will be
1 22 333 4444 55555
To solve this, we will follow these steps −
- for i in range 1 to n, do
- display (integer part of (10^i)/9*i)
- go to next line
Example
Let us see the following implementation to get better understanding −
def solve(n): for i in range(1,n+1): print((10**i)//9*i) n = 8 solve(n)
Input
8
Output
1 22 333 4444 55555 666666 7777777 88888888