+ 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

7th Jul 2021, 12:24 PM
Student
Student - avatar
4 Respuestas
+ 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
7th Jul 2021, 2:22 PM
Hatsy Rei
Hatsy Rei - avatar
+ 6
Do you need any help with the code you posted?
7th Jul 2021, 1:15 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Yes, I think my last while loop code is incorrect can you please rectify it.
7th Jul 2021, 1:17 PM
Student
Student - avatar
0
Yes it's working perfect Thanks Happy coding!
7th Jul 2021, 2:30 PM
Student
Student - avatar