if n=2
JavaScript
x
5
1
* *
2
* *
3
* *
4
* *
5
if n=3
JavaScript
1
10
10
1
* * *
2
* * *
3
* * *
4
* * *
5
* * *
6
* * *
7
* * *
8
* * *
9
* * *
10
This code i written for. But this code is half this only print row and column not space condition.
JavaScript
1
10
10
1
n = int(input (": "))
2
i = 0
3
for i in range (n**2):
4
j = 0
5
for j in range (n):
6
j+=1
7
print ("* " , end="")
8
i+=1
9
print ("")
10
Advertisement
Answer
You should remove i = 0
, i += 1
, j = 0
, and j += 1
. These operations happen by default in for
loops.
JavaScript
1
11
11
1
n = int(input(": "))
2
for i in range(n ** 2):
3
4
for k in range(i % n):
5
print(" ", end="")
6
7
for j in range(n):
8
print("* ", end="")
9
10
print("")
11
Or you can make your string first, then print it:
JavaScript
1
5
1
n = int(input(": "))
2
for i in range(n ** 2):
3
line = ((i % n) * ' ') + (n * '* ')
4
print(line)
5