- 1
how to print the following pattern using while and for loops: 5#\r 45#\r 345#\r 2345#\r 12345
12 Réponses
+ 5
print(r'#\r '.join(list(str('12345'[4-i:]) for i in range(5))))
+ 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()
+ 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
+ 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 >>
+ 3
No needs of 'if' with a 'while' loop, neither a 'for' one ^^
+ 2
i = 5
while (i):
j = i
while (j<6):
print(j,end='')
j += 1
print()
i -= 1
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
- 1
this time it's using while and if loop
- 1
u only used while..I asked with both while and if
- 1
not for loop ...if and while
- 1
ok thanks