GRAND ASSIGNMENT - 2 Right Triangle
Right Triangle
Given a number N, write a program to print a triangular pattern of N lines with numbers as shown below.
Input
The input will be a single line containing a positive integer (N).
Output
The output should be N rows with numbers.
Note: There is no space between the numbers.
Explanation
For example, if the given number of rows is 4,
your code should print the following pattern
Input
The input will be a single line containing a positive integer (N).
Output
The output should be N rows with numbers.
Note: There is no space between the numbers.
Explanation
For example, if the given number of rows is 4,
your code should print the following pattern
1
121
12321
1234321
Sample Input 1Sample Output 1
4
1 121 12321 1234321
Sample Input 2Sample Output 2
9
1 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321 12345678987654321
n=int(input())
for i in range(1,n+1):
for j in range (1,i+1):
print(j,end="")
for j in range (i-1, 0,-1):
print(j,end="")
print()
Comments
Post a Comment