How to print a string multiple times?
So I take it if the user enters 2
, you want the output to be something like:
!!
!!
!!
!!
Correct?
To get that, you would need something like:
rows = 4
times_to_repeat = int(raw_input("How many times to repeat per row? ")
for i in range(rows):
print "!" * times_to_repeat
That would result in:
How many times to repeat per row?
>> 4
!!!!
!!!!
!!!!
!!!!
I have not tested this, but it should run error free.
If you want to print something = '@'
2 times in a line, you can write this:
print(something * 2)
If you want to print 4 lines of something, you can use a for loop:
for i in range(4):
print(something)
It amazes me that this simple answer did not occur in the previous answers.
In my viewpoint, the easiest way to print a string on multiple lines, is the following :
print("Random String \n" * 100)
, where 100 stands for the number of lines to be printed.
for i in range(3):
print "Your text here"
Or
for i in range(3):
print("Your text here")