I m trying to create the below pattern using the below code
7
4 8
2 5 9
1 3 6 10
def createpattern(n=4,max_val=10):
pattern = []
for x in range(1,n+1):
temp = []
step = 2
val = x
bool_flag = 1
while bool_flag == 1:
temp += [val]
if val == max_val:
print('----->')
bool_flag = 0
print('before break')
break
else:
val = val + step
step += 1
print('after break')
print(temp)
max_val = max_val - 1
pattern.append(temp)
The break under while loop is working as expected
I m able to generate the first row however , the range in for loop is not moving to the next iteration value it is stuck at 1.
I have tried adding a continue at the end after append , however the loop is still stuck.
I m unable to figure out a way to rectify the above nested loop , ideally it should move to the next iteration value which I m unable to figure out why
Any leads would be helpful