Back

Code Kata -Patterns

Created 3 years ago
74 Views
1 Comments
AkshayaSrikanth
@AkshayaSrikanth
AkshayaSrikanth
@AkshayaSrikanthProfile is locked. Login

Write a code to generate a number half pyramid pattern.

Input Description:
Given an integer R indicates number of rows.

Where 1<=R<=100

Output Description:
Print the number half pyramid pattern based on the given integer R.

Sample Input :
5
Sample Output :
1
2 9
3 8 10
4 7 11 14
5 6 12 13 15

My CODE:
n=int(input())

l=[]

for i in range(1,n+1):

master=[]

for j in range(1,i+1):

if j==1:

master.append(i)

elif j==2:

master.append(i+j+2)

elif j==3:

master.append(i+j+4)

else:

master.append(i+j+5)

l.append(master)

#print(l)

for k in range(n):

for m in range(k+1):

if m%2==0:

print(l[k][m],end=" ")

else:

print(l[n-k][m],end=" ")

print()

OUTPUT FROM MY CODE:

>>> Compiling your code
Output:
1 
2 9 
3 8 10 
4 7 11 

Unable to figure out where the logic is going wrong... any suggestions/alternatives to solve this problem?


Comments
Please login to comment.