python pattern for value of N

Advertisements

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.

>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

Leave a ReplyCancel reply