Answer to Question #320333 in Python for hari

Question #320333

combined right angled triangles pattern:

you are given n. print n rows starting from 1 after combining two inverted-right-angled triangles pattern as shown in the output of the given example

explanation : 1st inverted right angled triangle pattern

1 2 3 4

5 6 7

8 9

10

2nd inverted right angled triangle pattern

17 18 19 20

14 15 16

12 13

11

combined pattern

1 2 3 4 17 18 19 20

5 6 7 14 15 16

8 9 12 13

10 11

input : n=4

output:

1 2 3 4 17 18 19 20

5 6 7 14 15 16

8 9 12 13

10 11

input: 5

output:

1 2 3 4 5 26 27 28 29 30

6 7 8 9 22 23 24 25

10 11 12 19 20 21

13 14 17 18

15 16


1
Expert's answer
2022-03-29T11:40:26-0400
n = int(input("Input n: "))
num1 = 0
num2 = n * (n + 1)
for i in range(n):
    for j in range(n-i):
        num1 += 1
        print(num1, end=" ")
    for j in range(n-i):
        print(num2 - n + j + 1, end=" ")
    num2 = num2 - n + i + 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