Answer to Question #233861 in Python for srikanth

Question #233861
Trapezium Order

you are given an integer N . print N rows starting from 1 in the trapexium 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 -seperated integers as per the trapezium order

Sample input:
4

Sample output:
 1 2 3 4 17 18 19 20
  5 6 7 14 15 16
   8 9 12 13
    10 11

please provide the correct output and also correct spaces also given.
1
Expert's answer
2021-09-06T05:29:02-0400
n = int(input())
mx = n*(n+1)
lst = [i+1 for i in range(mx)]
start = 0
stop = len(lst)
for i in range(n,0,-1):
	print(*(lst[start:start+i] + lst[stop-i:stop]))
	print(' '*(n-i+1),end='')
	start += i
	stop -= i

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