Answer to Question #176596 in Python for adhi chinna

Question #176596

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

1
121
12321
1234321
1
Expert's answer
2021-03-31T18:00:44-0400
n = int(input("Enter positive integer N: "))
j=1
for i in range(1,n+1):
    while j<=i-1:
        print(j,end = '')
        j+=1
    while j>0:
        print(j,end = '')
        j-=1
    j=1
    print("\n")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS