Answer to Question #226187 in Python for saii

Question #226187

Trapezium Order


You are given an integer N Print N rows starting from 1 in

the trapezium order as shown in the output of the below examples.


Input

The input contains an integer N.

Output

The output should have N lines.

Each of the N lines should have space-separated stegers as per the trapezium order.


Sample Input 1

4

Sample Output 1

1 2 3 4 17 18 19 20

5 6 7 14 15 16

8 9 12 13

10 11

see correct need exact pyramid,with give any input number..

1
Expert's answer
2021-08-15T01:15:58-0400
N= int(input())
leftTerm = 1
rightTerm = N * N + 1
  
for i in range(N, -1, -1):
    for _ in range(N, i-1, -1):
        print(" ", end ="")
    for j in range(1, i + 1): 
        print(str(leftTerm)+" ", end ="")
        leftTerm += 1
 
    for j in range(1, i + 1): 
        print(rightTerm, end ="")
        if j < i:
            print(" ", end ="")
        rightTerm += 1
        
    rightTerm =rightTerm- (i - 1) * 2 - 1 
    print()





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
New on Blog
APPROVED BY CLIENTS