Reputation: 9
size = int(input("please enter an integer:"))
for row in range(size*1):
print("*", end="")
print()
for column in range(1* size):
print("*", end="")
print()
This is my code so far and I need it to print: for 2
**
**
and for 7
*******
*******
*******
*******
*******
*******
*******
I have gotten it to print
**
**
for 2 but for 7 I just get
*******
*******
Upvotes: 0
Views: 90
Reputation: 1502
Another way is to simply multiply strings - no loops:
size = int(input("please enter an integer:"))
print((('*'*size)+'\n')*size)
enjoy :D :D :D
Upvotes: 0
Reputation: 51044
The natural way to write this in many languages would use a nested loop. However, it is much easier in Python:
for i in range(size):
print('*' * size)
Upvotes: 1
Reputation: 11717
You need to nest the two loops to achieve what you desire.
You can do it the following three lines with two tricks:
"*" * size
, therefore you need a single loopfor
loop does not need an index, that is not used, so you can use _
The code looks like this:
size = int(input("please enter an integer:"))
for _ in range(size):
print("*" * size)
Upvotes: 0
Reputation: 4733
You need to nest the for loops since you want the number of lines to be equal to the number of columns:
size = int(input("please enter an integer:"))
for row in range(size):
for col in range(size):
print('*', end="")
print()
PS: You don't really have to mulitply by 1 in range
.
Upvotes: 0