+ 1
Code: triangle of numbers(help to correct this code)
Print the following pattern for the given number of rows. Pattern for N = 4 1 232 34543 4567654 My code- n= int(input()) i=1 while i<=n: s=1 while s<=n-i: print(' ',end='') s=s+1 num=1 p=i while num<=i: print(p,end='') num=num+1 p=p+1 p=i-1 while p>=1: print(p,end='') p=p-1 print() i=i+1
4 ответов
+ 6
I haven't fully gone through the code, but by looking at the results I did manage to get it to work as expected by introducing an offset to the third loop nested within.
n= int(input())
i=1
while i<=n:
s=1
while s<=n-i:
print(' ',end='')
s=s+1
num=1
p=i
while num<=i:
print(p,end='')
num=num+1
p=p+1
p=i-1
while p>=1:
print(p+i-1,end='')
p=p-1
print()
i=i+1
+ 6
Do you need any help with the code you posted?
+ 1
Yes, I think my last while loop code is incorrect can you please rectify it.
0
Yes it's working perfect
Thanks
Happy coding!