- 1

how to print the following pattern using while and for loops: 5#\r 45#\r 345#\r 2345#\r 12345

8th Aug 2017, 6:07 AM
Shreyas
Shreyas - avatar
12 Respuestas
+ 5
print(r'#\r '.join(list(str('12345'[4-i:]) for i in range(5))))
8th Aug 2017, 6:58 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
Why posting again same aswered question? @@ https://www.sololearn.com/Discuss/592649/how-to-print-the-following-pattern-in-JUMP_LINK__&&__python__&&__JUMP_LINK-5-n-45-n-345-n-2345-n-12345 for i in range(5,0,-1): for j in range(i,6): print(j,end='') print()
8th Aug 2017, 6:53 AM
visph
visph - avatar
+ 3
# Mix both solutions ^^ for i in range(5,0,-1): j = i while (j<6): print(j,end='') j += 1 print() # or: i = 5 while (i): j = i for j in range(i,6): print(j,end='') print() i -= 1
8th Aug 2017, 7:11 AM
visph
visph - avatar
+ 3
You say 'for' loop in your question, and 'if' isn't a loop @@ @Shreyas wrote: << how to print the following pattern using while and for loops: 5#\r 45#\r 345#\r 2345#\r 12345 >>
8th Aug 2017, 7:13 AM
visph
visph - avatar
+ 3
No needs of 'if' with a 'while' loop, neither a 'for' one ^^
8th Aug 2017, 7:14 AM
visph
visph - avatar
+ 2
i = 5 while (i): j = i while (j<6): print(j,end='') j += 1 print() i -= 1
8th Aug 2017, 6:58 AM
visph
visph - avatar
8th Aug 2017, 11:13 AM
Roshan Kumar
Roshan Kumar - avatar
0
this ans is for beginners n = int(input()) i = 1 while 0 < i <= n: j = n-i+1 while 0 < j <= n: print(j,end='') j = j + 1 print() i += 1
17th Jan 2022, 11:55 PM
HARSH
- 1
this time it's using while and if loop
8th Aug 2017, 6:56 AM
Shreyas
Shreyas - avatar
- 1
u only used while..I asked with both while and if
8th Aug 2017, 7:07 AM
Shreyas
Shreyas - avatar
- 1
not for loop ...if and while
8th Aug 2017, 7:11 AM
Shreyas
Shreyas - avatar
- 1
ok thanks
8th Aug 2017, 7:16 AM
Shreyas
Shreyas - avatar