'Can anyone help me create a nested loop with an increment?
What I mean is a nested loop that will print out symbols. The number of symbols should be determined by incrementing the rows. At the same time the column of symbols should run for a set number before moving to the next number. The outcome will look something like below.
@
@
@@
@@
@@@
@@@
and so on.
Only managed to write this: rows = 5
outer loop
symbol = "@"
for i in range(rows):
# nested loop for j in range(i): print(symbol, end=' ')
print('') rows = 5
Tried this: rows = 2
outer loop
symbol = "@"
for i in range(rows):
# nested loop
for j in range(i):
print(symbol, end=' ')
print('') rows =2
I was expecting an output
@
@
@@
@@
@@@
@@@
Solution 1:[1]
I think you want this :
n = int(input())
for i in range(1,n+1):
for j in range(1,i+1):
print("@"*i)
output:
Edited :
I think you want as many as n repeat @ So this is :
n = int(input())
for i in range(1,n+1):
for j in range(1,n+1):
print("@"*i)
output:
This is a Matrix and you should play with it. it could be n*n or n*m means 2 * 2 or 2*3 or ...
for example this is n+1 * n :
n = int(input())
for i in range(1,n+2):
for j in range(1,n+1):
print("@"*i)
Solution 2:[2]
Thanks very much, @parisa-h-r. I added a separate input for the outer loop from the code you provided and it worked.
n = int(input("This is the row: "))
m = int(input("This is the column: "))
for i in range(n +1):
for j in range(m):
print("@"*i)
The output:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Parisa.H.R |




