Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python pattern for value of N

eg:
input : 3

output:

1
23
456
456
23
1

a = int(input())
p = 1
b = a
for i in range(0,a):
    for j in range(0,i+1)
          print(p,end=" ")
          p+=1
     print()
p-=1
for i in range(0,a):
     p-=b
     d = p
     for j in range(a-i,0,-1)
         print(p,end=" ")
         p+=1
     print()
     b-=1
     p = d

Can somesome debug my code to get the given output.
There is a small error in it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’re missing colons (:) in your for loop:

a = int(input())
p = 1
b = a
for i in range(0,a):
    for j in range(0,i+1):
        print(p,end=" ")
        p+=1
    print()

for i in range(0,a):
    p-=b
    d = p
    for j in range(a-i,0,-1):
        print(p,end=" ")
        p+=1
    print()
    b-=1
    p = d
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading