Answer to Question #225685 in Python for hari

Question #225685

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

CHECK THE LINK BELOW FOR EXACT OUTPUT

https://docs.google.com/document/d/1rMdPEY_1fttuydfFQLeJHmX_eMa66awj84hW2pnAdyI/edit


note : in the output second row 2 below there should be 5 and 3 below there should be 6 and likewise respected third row there should be 6 below there should be 8 and so on


1
Expert's answer
2021-08-13T02:03:30-0400
num = int(input("Number of lines: "))
lterm = 1
rterm = num * num + 1
  
for i in range(num, -1, -1):
        
    for space in range(num, i-1, -1):
        print(" ", end ="")
  
    for j in range(1, i + 1): 
        print(str(lterm)+" ", end ="")
        lterm += 1
 
    for j in range(1, i + 1): 
        print(rterm, end ="")
        if j < i:
            print(" ", end ="")
        rterm += 1
        
    rterm = rterm - (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